Home > Back-end >  For this application only a ticket booth MAO? Your brother do me a favor
For this application only a ticket booth MAO? Your brother do me a favor

Time:09-26

The class implements A Runnable
{
Public int tickets=100;
String STR=new String (" aa ");
Public void the run ()
{
While (true)
{
Synchronized (STR)
{
If (tickets> 0)
{
System. Out. Printf (" % s to buy out the first ticket \ n % d ", Thread. The currentThread (). The getName (), tickets);
- the tickets;
}
The else
{
break;
}
}
}
}
}


Public class Test_44
{
Public static void main (String [] args)
{
A aa=new A ();
Thread the t1=new Thread (aa);
T1. Start ();

Thread t2=new Thread (aa);
T2. Start ();
}
}
  • Related