IDE是Eclipse,語言是JAVA,Release下執行,
a的結果是5,確定是有至run()函式中執行,可是在Debug模式下,
卻無法跳至run()函式中,似乎 跟mthread.join();這行有關,
請問有人知道為什麼嗎?
public class mythread implements Runnable{
public static int a = 0;
public void run() {
for (int k = 0; k < 5; k++) {
a = a + 1;
}
}
public static void main(String[] args) throws Exception {
Runnable r = new mythread();
Thread mthread = new Thread(r);
mthread.start();
mthread.join();
System.out.println(a);
}
}