开发者

How to fix Naked notify warning of FindBugs?

开发者 https://www.devze.com 2023-02-14 15:44 出处:网络
I have Naked notify warning of FindBugs. The below is my code. synchronized (this) { this.notify(); } The \"this\" is \"public class Controller extends Thread\".

I have Naked notify warning of FindBugs. The below is my code.

synchronized (this) {
        this.notify();
    }

The "this" is "public class Controller extends Thread". How to fix the warning?? I have no idea for it.

开发者_如何学JAVA

Thanks in advance.


The naked notify warning means that using the notify() method implies that there is some other thread waiting for some mutable state to change, and is waiting to be notified. But your synchronized block did not modify any mutable state, and so it seems odd that you would need the notify. If you modified the state of an object outside of the synchronized block, then it seems dubious that this code is thread safe, as there is another thread that is reading this data

0

精彩评论

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