Java并发编程实战(使用synchronized实现同步方法)(二)

2015-07-26 20:41:53 · 作者: · 浏览: 153
int the final balance
? ? ? ? ? ? System.out.printf("Account : Final Balance: %f\n",account.getBalance());
? ? ? ? } catch (InterruptedException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }
}


结果,相同时间内,存与取执行后应该是相等的。如果我们在方法中不去使用synchronized关键字,那么得出的结果就不对了。
  
  Account : Initial Balance: 1000.000000
  Account : Final Balance: 1000.000000