线程同步的诡异:求指点

public class BUYER {
 public static void main(String[] args) { 
  TestThread a=new TestThread(); 
  TestThread B=new TestThread();
  a.setName("A");
  B.setName("B");
  a.start();  
  B.start();
 }
}
class TestThread extends Thread
{
 static int Rest=10;//剩余票数
 int buy_1=7;//购买票数
 
 public void run(){
  int a=Rest;
  if(a>buy_1){ 
   a=a-buy_1; 

Rest=a; //①为什么该语句放在这里永远无法出现同时购票成功的情况

   System.out.println(Thread.currentThread().getName()+"\n Success .");  
   //  ② Rest=a; 
    }else
   System.out.println(Thread.currentThread().getName()+"\n fail .");

}
}

//①处售票的情况处理永是真确的.②处售票的情况处理可能出现同时成功的现象?

知道何解的mankind求指点下.

posted @ 2015-04-28 11:50  blackplume  阅读(106)  评论(0编辑  收藏  举报