【发布时间】:2015-08-13 09:32:36
【问题描述】:
class A implements Runnable{
int i=0;
public void run(){
System.out.println("Thread-"+i++);
}
}
class Demo {
public static void main(String []args) {
A a=new A();
Thread t1=new Thread(a);
Thread t2=new Thread(a);
Thread t3=new Thread(a);
t1.start();
t2.start();
t3.start();
}
}
谁能解释一下这段代码是如何执行的以及输出是什么?
【问题讨论】:
-
为什么不直接运行一下试试?
-
@Simz 实验并不一定会导致理解。我认为这将是一个很好的主题问题,它会不会是同类的第 1000 个化身,使其明显重复。
标签: java multithreading concurrency