As @Mike is saying, creation of enum is guaranteed to be thread safe. However, methods that you add to an enum class do not carry any thread safety guarantee. In particular, the method leaveTheBuilding
may be executed, concurrently, by multiple threads. If this method has side effects (changes the state of some variable) then you need to think about protecting it (i.e., make it synchronized
) or parts thereof.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…