【发布时间】:2014-02-18 20:09:40
【问题描述】:
多线程访问时我有静态方法,会不会数据更新不正确,
public class A
{
private static B b=null;
public static B create()
{
b= new B();
return b;
}
public static B process()
{
// doing some processing with b;
return b;
}
}
如果多个线程同时访问,B会不会受到影响?
【问题讨论】:
-
查看 synchronized()、易失性和可能的线程安全单例模式。
-
该代码甚至无法以当前形式编译..
标签: java multithreading static