SaleTicktes

class Ticktes implements Runnable
{
 private int tick = 250;
 //String str = new String("hehe");

 public void run()
 {

  while (true)
  {
   synchronized (this)
   {
    if (tick >= 0)
    {

     System.out.printf("%s正在卖第%d张票/n", Thread.currentThread().getName(), this.tick);
     tick--;
    }
    else
    {
     break;
    }
   }
  }
  

 }
}

class SaleTicktes
{
 public static void main(String[] args)
 {
  Ticktes t = new Ticktes();
  Thread saleTicktes = new Thread(t);
  saleTicktes.setName("售票站点1: ");
  saleTicktes.start();

  Thread saleTicktes1 = new Thread(t);
  saleTicktes1.setName("售票站点2: ");
  saleTicktes1.start();

  Thread saleTicktes2 = new Thread(t);
  saleTicktes2.setName("售票站点3: ");
  saleTicktes2.start();

  Thread saleTicktes3 = new Thread(t);
  saleTicktes3.setName("售票站点4: ");
  saleTicktes3.start();

 }
}

你可能感兴趣的:(thread,String,Class)