详细描述This method contains an unsynchronized lazy initialization of a static field. After the field is set, the object stored into that location is further updated or accessed. The setting of the field is visible to other threads as soon as it is set. If the futher accesses in the method that set the field serve to initialize the object, then you have a very serious multithreading bug, unless something else prevents any other thread from accessing the stored object until it is fully initialized. Even if you feel confident that the method is never called by multiple threads, it might be better to not set the static field until the value you are setting it to is fully populated/initialized. 有谁能解释下吗?一直对这个问题很模棱两可,不胜感谢
{
if(oneclassname == null)
{......} }
}
不明白有啥多线程的问题啊?
改成private
final才不能被更改
public static 的,就是把自己暴露出去,谁爱用谁用吧~~
参考里面火龙果的回答。不过,除非确实占据了太多资源,需要lazyload,否则,直接static final XXX INSTANCE = new XXX();或者static final XXX INSTANCE;
static {
INSTANCE = foo();
}