标签:style blog http ar color sp java div 2014
class Mlpc extends Thread //第一步、定义类继承Thread类
{
private int ticket = 20;
public void run() //第二步、覆写run方法,把需要被现场运行的代码都写在其中
{
while(true)
{
if(ticket>0)
{
System.out.println(Thread.currentThread()+" "+ticket);
}
}
}
}
class mlpcDemo
{
public static void main(String[] args)
{
Mlpc m = new Mlpc();
Thread th0 = new Thread(m);
Thread th1 = new Thread(m);
Thread th2 = new Thread(m);
Thread th3 = new Thread(m);
th0.start();
th1.start();
th2.start();
th3.start();
}
}

标签:style blog http ar color sp java div 2014
原文地址:http://www.cnblogs.com/tozr/p/4148831.html