[英]How to fix Naked notify warning of FindBugs?
I have Naked notify warning of FindBugs. 我有FindBugs的Naked通知警告。 The below is my code.
以下是我的代码。
synchronized (this) {
this.notify();
}
The "this" is "public class Controller extends Thread". “this”是“public class Controller extends Thread”。 How to fix the warning??
如何修复警告? I have no idea for it.
我不知道。
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. 裸通知警告意味着使用notify()方法意味着有一些其他线程正在等待某个可变状态发生更改,并且正在等待通知。 But your synchronized block did not modify any mutable state, and so it seems odd that you would need the notify.
但是你的synchronized块没有修改任何可变状态,所以你需要通知它似乎很奇怪。 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
如果你修改了同步块之外的对象的状态,那么这个代码是线程安全的似乎是可疑的,因为有另一个线程正在读取这些数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.