Shutdown
void Shutdown ()
Starts a sequential shutdown, performs a previously submitted task, but does not accept new tasks. If it is already closed, the call has no other effect.
Thrown:
SecurityException-If the security manager exists and shuts down, this executorservice may manipulate some threads that do not allow the caller to modify (because it is not persisted RuntimePermission ("Modifythread")), or the security manager's CheckAccess method denies access.
isterminated
Boolean isterminated ()
* using a thread pool to open multiple sub-threads, the main thread waits for all child threads to execute */public static void morethread () {try {int threadNum = 0;for (int i = 0; i < 10; i++ ) {threadnum++;final int currentthreadnum = threadnum;exe.execute (New Runnable () {@Overridepublic void run () {try {system.out.println ("sub-thread [" + currentthreadnum + "] open"); Thread.Sleep (1000*10);} catch (interruptedexception e) {e.printstacktrace ();} Finally{system.out.println ("sub-thread [" + currentThreadNum + ] "end");}}); }system.out.println ("All sub-threads have been turned on"); Exe.shutdown (); System.out.println ("Shutdown (): Initiates a sequential shutdown, performs a previously submitted task, but does not accept new tasks. "); while (true) {if (exe.isterminated ()) {System.out.println (" All child threads are over! ") "); break;} Thread.Sleep (; }} catch ) (interruptedexception e) {e.printstacktrace (); Finally{system.out.println ("Main thread End");}}
Child thread [1] opening sub-thread [6] opening sub-thread [2] opening sub-thread [5] opening sub-thread [9] turning on all of the Cheng Zi threads [3] Opening a sub-thread [7] Opening a child thread [10] opening shutdown (): initiating a sequential shutdown, performing a previously submitted task, But do not accept new tasks. Child thread [4] opening a child thread [8] Opening a sub-thread [6] ending a child thread [3] ending a child thread [7] ending a child thread [2] ending a child thread [1] End Child thread [5] End Child thread [9] End Child thread [4] End child thread [10] End Child thread [8] End all child threads end! Main thread End
How Java determines if all the thread pool tasks are done