Professional Documents
Culture Documents
Dokumen - Tips Multithreading-Concept
Dokumen - Tips Multithreading-Concept
Jin Sa
}//SeveralThreads
…
mythread.start();
}
…
}
12/06/23 Client-server Programming 14
Implementing Runnable or
Extending Thread
• Use Runnable if need to extend another
class
• Even if NewTask does not extend another
class, this is the preferred method for
creating a thread if we only want to define
the run() method, and not using the other
methods in Thread.
deposit(10) Balance=50
deposit(10)
deposit(10)
deposit(10)
deposit(10)
deposit(10)
Problem with accessing shared
resources– an example 1
class Account {
private int balance=0;
c1.start();
c2.start();
}
}//FamilyAccount
Problem with accessing shared
resources– an example 4
• Run FamilyAccount in the E:clientserver/threads (account,cardholder,familyAccount)
System.out.println("Current balance is
"+balance);
}
}//Account