9

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.

user
  • 6,897
  • 8
  • 43
  • 79
mooongcle
  • 3,987
  • 5
  • 33
  • 42
  • Doesn't it tell you what the warning actually is? (And have you considered implementing Runnable instead of extending Thread?) – Jon Skeet Mar 04 '11 at 12:15
  • Just don't use the thread to sync. on. more on using threads to sync on: http://stackoverflow.com/questions/5121173/java-threads-wait-and-notify-methods/5121267#5121267 – bestsss Mar 04 '11 at 12:31

1 Answers1

10

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

Chin
  • 19,717
  • 37
  • 107
  • 164
MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66