Answer the question
In order to leave comments, you need to log in
Is it possible to lock two objects in a synchronized block?
public void transfer(int from, int to, double amount) {
synchronized (accounts) {//double[] accounts - массив счетов в банке
if (accounts[from] < amount) return;
accounts[from] -= amount;
accounts[to] += amount;
}
}
Answer the question
In order to leave comments, you need to log in
synchornize(accounts[Math.min(from, to)])
{
synchorize(accounts[Math.max(from, to)])
{
}
}
You can
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question