class T implements Runnable
{
Thread t1,t2;
T()
{
t1=new Thread(this);
t2=new Thread(this);
}
public void run()
{
if(Thread.currentThread()==t2)
{
t1.interrupt();
}
if(Thread.currentThread()==t1)
{
System.out.println("线程t1开始运行!");
try{
System.out.println("线程t1开始休眠10s!");
t1.sleep(10000);
}
catch(InterruptedException e)
{
System.out.println("线程t1被吵醒了!");
}
}
}
}
class A
{
public static void main(String args[])
{
T t=new T();
t.t1.start();
t.t2.start();
}
}
时间: 2024-10-12 07:31:36