class ThreadTest
{
public static void main(String[] args)
{ SendPaper a=new SendPaper();
Thread th1= new Thread(a,"老师1");
Thread th2= new Thread(a,"老师2");
Thread th3= new Thread(a,"老师3");
Thread th4= new Thread(a,"老师4");
th1.start();
th2.start();
th3.start();
th4.start();
}
}
class SendPaper implements Runnable//继承Runnable接口
{Object lock =new Object();
public void run()
{synchronized(lock)//同步锁标记
{
try{
for (int x=1;x<=80 ;x++ )
{System.out.println(Thread.currentThread().getName()+"发送第"+x+++"卷子");
Thread.sleep(100);}
}
catch(InterruptedException e){
e.printStackTrace();}
}
}
} |
|