如何修复FindBugs的Naked通知警告?
我有 FindBugs 的 Naked 通知警告。 下面是我的代码。
synchronized (this) {
this.notify();
}
“this”是“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.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
裸通知警告意味着使用notify()方法意味着有其他线程正在等待某些可变状态更改,并且正在等待通知。但是您的同步块没有修改任何可变状态,因此您需要通知似乎很奇怪。如果您在同步块之外修改了对象的状态,那么这段代码是否线程安全似乎值得怀疑,因为有另一个线程正在读取此数据
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