Java ThreadPoolExecutor prestartCoreThread() MethodThe preStartCoreThread() method of ThreadPoolExecutor class starts a core thread, causing it to idly wait for the work. This overrides the default policy of starting core threads only when new tasks are executed. SyntaxParametersNA ReturnThe true if a thread was started ThrowDoes not throw the exception. Example 1Test it NowOutput: Core Pool size after execution: 0 Running Thread Name: pool-1-thread-1 Running Thread Name: pool-1-thread-2 Completed Thread Name: pool-1-thread-2 Completed Thread Name: pool-1-thread-1 Example 2Test it NowOutput: Starting threads Threads started, main ends Thread sleeping for 1000 i=0 Thread sleeping for 1000 i=1 Thread sleeping for 1000 i=2 Thread sleeping for 1000 i=3 Thread sleeping for 1000 i=4 now i > 5 :
Next TopicJava ThreadPoolExecutor
|