k****r 发帖数: 807 | 1 不是很懂多线程,请教我这样的设计可以满足面试官对于deposit和withdraw的提问吗?
哪里可以找到代码学习学习,谢谢。
class bank2 {
private double balance;
private int acountNum;
private Object lock = new Object();
public bank2(int a, double b) {
acountNum = a;
balance = b;
}
public boolean withdraw(double w) {
synchronized(lock) {
if (balance < w) return false;
balance -= w;
return true;
}
}
public boolean deposit(double d) {
synchronize... 阅读全帖 |
|