本帖最后由 zc332750 于 2014-2-8 12:43 编辑
package demo;
class Ticket extends Thread{
private static int tickets = 100;
public void run(){
while(true){
if(tickets>0){
System.out.println(getName()+" 卖出的第"+tickets--+"张票");
}
}
}
}
public class ThreadDemo {
public static void main(String[] args) {
Ticket t1 = new Ticket();
Ticket t2 = new Ticket();
Ticket t3 = new Ticket();
Ticket t4 = new Ticket();
t1.start();
t2.start();
t3.start();
t4.start();
}
}
|
|