class Demo implements Runnable
{
public synchronized void run() {
try{wait();}
catch (InterruptedException e)
{
System.out.println(Thread.currentThread().getName()+"已经停止等待 抛出异常");
}
for(int i=0;i<10;i++)
System.out.println(Thread.currentThread()+"..."+i);
}
}
public class Main {
public static void main(String[] args)
{
Demo d1=new Demo();
Demo d2=new Demo();
Demo d3=new Demo();
//默认的线程组是main
ThreadGroup t=new ThreadGroup("线程组t");
Thread t1=new Thread(t,d1);
Thread t2=new Thread(t,d2);
Thread t3=new Thread(t,d3);
t1.start();
t2.start();
t3.start();
t.interrupt();
}
}
运行结果: