1 PackageXiancheng;2 3 Public classTest5Implementsrunnable{4 5 Static intpiaos=10;6 Public voidRun ()7 {8 //Sell Tickets9 while(true)Ten { One synchronized("") A { - if(piaos>=0) - { the Try { -Thread.Sleep (1000); - } - Catch(interruptedexception e) { + //TODO Auto-generated catch block - e.printstacktrace (); + } A at //System.out.println (Thread.CurrentThread (). GetName () + "number of votes left:" +piaos); - // -piaos--; - -System.out.println ( This. GetName () + "number of votes left:" +Piaos); - in } - Else to { +System.out.println ("End of Ticket"); - //Break ; the } * } $ }Panax Notoginseng - } the + PrivateString GetName () { A //TODO Auto-generated method stubs the return NULL; + } - $ Public Static voidMain (string[] args) { $ //TODO Auto-generated method stubs -Test4 p4=NewTest4 (); - theThread w1=NewThread (P4, "Ticket window One"); -Thread w2=NewThread (P4, "ticket window Two");WuyiThread w3=NewThread (P4, "ticket window three"); the W1.start (); - W2.start (); Wu W3.start (); - About $ } - -}
Ticket 3-implements Runnable