Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Naked notify warning of FindBugs?

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.

Thanks in advance.

like image 305
mooongcle Avatar asked Mar 04 '11 12:03

mooongcle


1 Answers

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

like image 121
MeBigFatGuy Avatar answered Nov 11 '22 00:11

MeBigFatGuy