//僅用于測試,無任何業務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();}}}
請問如下代碼是為什么?,非常感謝
ibeautiful
2022-10-20 15:15:38