This is best blog for software engineer can learn c, c++,Java,c# javascript ,vb script and sql query. All are basics for web application and applet
Wednesday, July 23, 2014
Deadlock in multithreading - Java
public class Account {
double balance;
int id;
Account(){
}
Account(double _balance,int _id){
balance=_balance;
id=_id;
}
void withdraw(double amount){
balance -= amount;
}
void deposit(double amount){
balance += amount;
}
void transfer(Account from, Account to, double amount){
synchronized (from) {
synchronized (to) {
from.withdraw(amount);
to.deposit(amount);
}
}
/* from.withdraw(amount);
to.deposit(amount); */
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment