class Ticket implements Runnable //extends Thread
{//1
private int num=1000;
Object obj=new Object();
boolean flag=true;
public synchronized void sale()
{//2
if(num>0)
{//3
//try{Thread.sleep(10);}
//catch (InterruptedException e){}
System.out.println(Thread.currentThread().getName()+"\t"+"show票号:"+num--);
}//3
}//2
public void run()
{//4
if(flag)
while(true)
{//5
synchronized(obj)
{//6
if(num>0)
{//7
try{Thread.sleep(10);}
catch (InterruptedException e){}
System.out.println(Thread.currentThread().getName()+"\t"+"obj票号:"+num--);
{//7
}//6
}//5
else
while(true)
sale();
}//4
}//1
class synchornizedFunctionLockDemo
{//8
public static void main(String[] args)
{//9
Ticket t=new Ticket();
Thread t1=new Thread(t);
Thread t2=new Thread(t);
t1.start();
t2.start();
}//9
}//8
{//1
private int num=1000;
Object obj=new Object();
boolean flag=true;
public synchronized void sale()
{//2
if(num>0)
{//3
//try{Thread.sleep(10);}
//catch (InterruptedException e){}
System.out.println(Thread.currentThread().getName()+"\t"+"show票号:"+num--);
}//3
}//2
public void run()
{//4
if(flag)
while(true)
{//5
synchronized(obj)
{//6
if(num>0)
{//7
try{Thread.sleep(10);}
catch (InterruptedException e){}
System.out.println(Thread.currentThread().getName()+"\t"+"obj票号:"+num--);
{//7
}//6
}//5
else
while(true)
sale();
}//4
}//1
class synchornizedFunctionLockDemo
{//8
public static void main(String[] args)
{//9
Ticket t=new Ticket();
Thread t1=new Thread(t);
Thread t2=new Thread(t);
t1.start();
t2.start();
}//9
}//8