进入同步块(synchronized block)时抛出IllegalStateException是什么意思?我有时会在线程的运行方法中看到这种情况:
public void run() {
while (true) {
int n = 0;
synchronized (service) { // IllegalStateException
n = processPendingRequests();
}
/*
* If n > 0, we processed at least one element, in which case we
* immediately check the queue again until it was empty.
*/
if (n == 0) {
sleep();
continue;
}
}
}
service
对象会导致 IllegalStateException
吗?怎么办?
最佳答案
根据Java Language Specification ,“synchronized”语句不会抛出“IllegalStateException”。因此,据我所知,要么语言规范是错误的,要么您使用了不合格的 JVM,要么您误解了程序的行为。
关于java - 尝试进入同步块(synchronized block)时出现 IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2297496/