public void someMethod(){
LocalObject localObject = new LocalObject();
localObject.callMethod();
method2(localObject);
}
public void method2(LocalObject localObject){
localObject.setValue("value");
}
是线程安全的。但我觉得
public class LocalObject extends Thread {
public void run(){
//LocalObject a= new LocalObject();
method2(this);
}
public void someMethod(){
LocalObject localObject = new LocalObject();
localObject.callMethod();
method2(localObject);
}
public void method2(LocalObject localObject){
localObject.setValue("value");
}
public void setValue(String s){
}
public void callMethod(){
}
public static void main(String args[]){
LocalObject a= new LocalObject();
a.start();
a.method2(a);
}
}
不是线程线程安全的,因为两个线程 1. main
& 2.LocalObject
的线程正在访问方法 2,它有一个方法setValue
我在哪里误解了它?