findbugs

总结下工作遇到的findbugs问题

The code synchronizes on a boxed primitive constant, such as an Boolean.

private static Boolean inited = Boolean.FALSE;
...
synchronized(inited) {
if (!inited) {
init();
inited = Boolean.TRUE;
}
}
...
Since there normally exist only two Boolean objects, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness and possible deadlock

该代码同步一个封装的原始常量,例如一个Boolean类型。

private static Boolean inited = Boolean.FALSE;

...

synchronized(inited) {

if (!inited) {

init();

  inited  = Boolean.TRUE;

  }

}

...

由于通常只存在两个布尔对象,此代码可能是同步的其他无关的代码中相同的对象,这时会导致反应迟钝和可能死锁

解释 http://www.jb51.net/article/73787.htm

你可能感兴趣的:(findbugs)