即使在调用run()2次后,为什么我的计数还没有增加?为什么即使在调用run()2次后,我的计数也不会增加?
public class Test extends Thread{
private int i;//default value is 0
public void run(){
i++;//increas value of i by 1
}
public static void main(String[] args){
Test a = new Test();
System.out.println(a.i); // prints 0
a.run();//direct call
System.out.println(a.i);// prints 1
a.start();// calls run()
System.out.println(a.i);// again prints 1
}
}
@Tacolibre'Test extends Thread' – QBrute
您只能调用'run()'一次。 –
也许最后一个'println'发生在线程启动之前。 –