//仅用于测试,无任何业务
public class DateFormat2 {
public static SimpleDateFormat parse(){
SimpleDateFormat adf=new SimpleDateFormat ();
return adf
}
}
//多线程测试上述方法,局部变量应该在线程栈中,每个线程访问该方法后都new一个对象,应该是不同的引用地址,但结果却不是,测试方法如下
public class Test {
public static class TestSimpleDateFormatThreadSafe extends Thread {
@Override
public void run() {
while(true) {
try {
this.join(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
System.out.println(this.getName()+":"+DateFormat2.parse());
} catch (ParseException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) throws ParseException {
for (int i = 0; i <3; i++) {
new TestSimpleDateFormatThreadSafe().start();
}
}
}
请问这是为什么?,非常感谢