Java ThreadPoolExecutor shutdownNow() MethodThe shutdownNow () method of ThreadPoolExecutor class attempts to stop all the tasks which are executing actively, halts the processing of waiting tasks and returns a list of the tasks that were awaiting execution. SyntaxParametersmaximumPoolSize - the new maximum Returnlist of tasks that never commenced execution ThrowSecurityException Example 1Test it NowOutput: Is Executor is shutdown :false get Task count after:2 Is Executor is shutdown :true Running Thread Name: pool-1-thread-1 Running Thread Name: pool-1-thread-2 Example 2Test it NowOutput: Starting threads Maximum pool size: 2147483647 get Task count before:0 i=5 Is Executor is shutdown :true Threads started, main ends i=5
Next TopicJava ThreadPoolExecutor
|