1 /*2 The following program will appear below, when Thread-0, Thread-1, Thread-2 are wait, they may wake up at the same time3 Thread-0 put4 Thread-1 put5 Thread-2 put6 Thread-3 get//Here, Thread-3 get the lock, wake up all the waiting threads and have the following output7 Thread-2 put8 Thread-1 put9 Thread-0 putTen */ One A - Although multiple threads will wake up at the same time, only one can get the CPU execution right! - in short, the synchronization can only be performed in one, but the survival is not necessarily one! the - - classduckd{ - Public voidput () { + -Synchronized (DUCKD.class){ + ASystem. out. println (Thread.CurrentThread (). GetName () +"put"); at Try{ -DUCKD.class. Wait ();//Thread-0, Thread-1, Thread-2 may wake up here at the same time! -}Catch(interruptedexception e) { - - } - //........ in } - } to + Public void Get(){ - theSynchronized (DUCKD.class){ * $DUCKD.class. Notifyall ();Panax NotoginsengSystem. out. println (Thread.CurrentThread (). GetName () +"Get"); - Try{ theDUCKD.class. Wait (); +}Catch(interruptedexception e) { A the } + } - } $ } $ - classproduced implements Runnable{ - duckd dk; the produced (Duckd dk) { - This. dk=dk;Wuyi } the Public voidrun () { - while(true) Wu dk.put (); - } About } $ - classconsumed implements runnable{ - duckd dk; - consumed (duckd dk) { A This. dk=dk; + } the Public voidrun () { - while(true) $Dk.Get(); the } the } the the classtest{ - Public Static voidMain (string[] args) { inDUCKD dk=Newduckd (); theThread t1=NewThread (Newproduced (DK)); theThread t2=NewThread (Newproduced (DK)); AboutThread t3=NewThread (Newproduced (DK)); theThread t4=NewThread (Newconsumed (DK)); the the T1.start (); + T2.start (); - T3.start (); the T4.start ();Bayi } the}