This is a very interesting program, I wrote an example of 10 sub-threads, you can refer to: public class test {static test test = null; static int cellnum = 0; synchronized static void decSem () {childne--; if (childnum == 0) {synchronized (test) {test.notify ();}}}
Test () {test = this;} void connectDB () throws InterruptedException {synchronized (this) {childNum = 10; new TestThread () start ();. New TestThread () start ();.. New TestThread () start ( NEW TESTTHREAD (). Start (); new testthread (). Start (); new testthread (). Start (); new testthread (). Start (); new testthread (). Start (); new testthread (). START (); new testthread ) .Start (); new testthread (). start (); wait ();}} public static void main (string [] args) throws interruptedException {system.out.println ("start ..."); test test = new test (); test.connectdb (); system.out.println ("end.");}}
Class testthread extends thread {public void run () {super.run (); system.out.println ("child thread"); test.decsem ();}}