【发布时间】:2011-10-03 21:29:18
【问题描述】:
以下两个方法定义在语义上是等价的吗?为什么?为什么不呢?
版本 A:
private static synchronized void foo() {
bar();
}
B 版:
private static Semaphore available = new Semaphore(1, true);
private static void foo() {
available.acquire();
try {
bar();
}
finally {
available.release();
}
}
【问题讨论】:
标签: java multithreading concurrency jvm semaphore