开发者

IllegalStateException while attempting to enter synchronized block

开发者 https://www.devze.com 2022-12-20 13:18 出处:网络
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:

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

精彩评论

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

关注公众号