本帖最后由 U芽Lady 于 2013-4-21 22:06 编辑
class Demo implements Runnable{
private int x = 20;
Object p = new Object();
public void run(){
synchronized(p){
while(x>0){
try{
Thread.sleep(1000);
}catch(Exception e){}
//for(int y = -99999999;y<99999999;y++){}
System.out.println(Thread.currentThread().getName() + "..." + x--);
}
}
}
}
class ThreadDemo1 {
public static void main(String[] args) {
Demo d = new Demo();
Thread t1 = new Thread(d);
Thread t2 = new Thread(d);
Thread t3 = new Thread(d);
Thread t4 = new Thread(d);
/*
t1.setName("8");
t2.setName("2");
t3.setName("3");
t4.setName("4");
*/
t1.start();
t2.start();
t3.start();
t4.start();
}
}
/*怎么只运行了一个线程呢,麻烦大神们帮忙调试一下,在此谢过
*/
|