多线程——卖票

public class 卖票 {
 public static void main(String[] args) {
  piao piao=new piao();
  new Thread(piao,"1号床").start();
  new Thread(piao,"2号床").start();
  new Thread(piao,"3号床").start();
 }
}
class piao implements Runnable{
 private int PP=100;
 
@Override
 public void run() {
  while(PP>0){
   Thread thread=Thread.currentThread(); //使用一个当前线程
   String ThWindow=thread.getName(); //get线程名字
   System.out.println(ThWindow+": 第张"+PP--+"票");
  }
 } 
}

你可能感兴趣的:(Java)