进入同步块时抛出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,“已同步”语句不会引发“ IllegalStateException”。因此,就我所知,语言规范是错误的,您使用的是不合格的JVM,还是您误解了程序的行为。

关于java - 尝试输入同步块(synchronized block)时发生IllegalStateException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2297496/

10-11 17:59