开发者

IllegalStateException while attempting to enter synchronized block

What does it mean when a IllegalStateException is thrown when entering a synchronized block? I'm seeing this sometimes inside the run-method of a thread:

    public void run() {
        while (true) {
            int n = 0;
            synchronized (service) { // Illeg开发者_运维知识库alStateException
                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;
            }
        }
    }

Can the service object cause the IllegalStateException? How?


According to the Java Language Specification, the "synchronized" statement doesn't throw an "IllegalStateException". Therefore, either the Language Specification is wrong, you're using a non-conforming JVM, or you've misinterpreted the behavior of your program -- as far as I can see.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜