public class StaticClassTest{
private static int count = 0;
public static int addAndGet(){
count ++;
return count;
}
}
public class StatelessClass{
public int get(){
return StaticClassTest.addAndGet();
}
}
类似于上面两个类,第一个类是线程不安全的类,第二个类是无状态的类,那么第二个类是否是线程安全的?
public class StaticClassTest{
private static int count = 0;
public static int addAndGet(){
count ++;
return count;
}
}
public class StatelessClass{
public int get(){
return StaticClassTest.addAndGet();
}
}