1.
1 Public classSyncDubbo2 {2 Static classsup{//Parent Class3 Public inti = 10;4 Public synchronized voidOpersup () {5 Try{6i--;7SYSTEM.OUT.PRINTLN ("Sup parent class print i=" +i);8Thread.Sleep (1000);9}Catch(interruptedexception e) {Ten e.printstacktrace (); One } A } - } - the Static classSubextendssup{//sub-class - Public synchronized voidopersub () { - Try { - while(I > 0){ +i--; -System.out.println ("sub-subclass print i=" +i); +Thread.Sleep (1000); A This. Opersup (); at } -}Catch(Exception e) { - e.printstacktrace (); - } - } - } in - Public Static voidMain (string[] args) { toThread T1 =NewThread (NewRunnable () { + @Override - Public voidrun () { theSub Sub =NewSub (); * sub.opersub (); $ }Panax Notoginseng}, "T1"); - the T1.start (); + } A the /* + Sub Sub-category print I=9 - SUP Parent class print i=8 $ Sub Sub-category print I=7 $ SUP Parent class print I=6 - Sub Sub-category print I=5 - SUP Parent class print i=4 the Sub Sub-category print I=3 - SUP Parent class print i=2Wuyi Sub Sub-category print I=1 the SUP Parent class print i=0 - */ Wu}
View Code
Multi-threaded 6---Re-entry lock 2