I was looking through a Findbugs report on my code base and one of the patterns that was triggered was for an empty synchronzied
block (i.e. synchronized (var) {}
). The documentation says:
Empty synchronized blocks are far more
subtle and hard to use correctly than
most people recognize, and empty
synchronized blocks are almost never a
better solution than less contrived
solutions.
In my case it occurred because the contents of the block had been commented out, but the synchronized
statement was still there. In what situations could an empty synchronized
block achieve correct threading semantics?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…