我想用java多线程同步机制写段卖火车票的程序:
import java.io.*;
import java.util.*;
import java.lang.Thread;
import java.lang.Runnable;class SellThread extends Thread
{  private static int tickets;
  public SellThread()  {
       tickets=100;
  }  public void run()  {
     while(true)
     {
       
       synchronized(this)       {
       if (tickets>0)       {        System.out.println(Thread.currentThread().getName()+"sellticket"+tickets);
        
        tickets--;
       }
       else
        
       break;
       }
     }    
         
     
  }
    
    
   
  
}public class TicketsSystemCo{   public static void main(String[] args)
{   SellThread st1=new SellThread();
   
   st1.start();   SellThread st2=new SellThread();
   
   st2.start();   SellThread st3=new SellThread();
   
   st3.start();
   
   
}}
但结果还是有票被重复卖了