帮忙看下线程问题
xuqq 2004-08-09 10:19:08 执行过程是怎样的
t1.start();会如何引导程序
run是怎样被调用的
谢谢
程序如下:
public class Thread2 implements Runnable {
int threadNumber;
public Thread2(int i) {
System.out.println(" Making thread=" + i);
threadNumber=i;
}
public void run() {
for(int i=0; i<3; i++) {
System.out.println(" Running thread number=" + threadNumber);
try {
Thread.sleep((int)(Math.random() * 1000));
}
catch ( InterruptedException ex ) {
System.err.println(ex.toString());
}
}
}
public static void main(String[] args) {
Thread t1, t2;
t1=new Thread(new Thread2(1));
t1.start();
t2=new Thread(new Thread2(2));
t2.start();
System.out.println(" End of main");
}
}