Java ThredPoolExecutor getKeepAliveTime() MethodThe getKeepAliveTime() of ThreadPoolExecutor class is used to calculate the thread keep-alive time, which is the amount of time the threads may remain idle before being terminated. SyntaxParametersunit - the desired time unit of the result Returnthe time limit ThrowDoes not throw exception. Example 1Test it NowOutput: Starting threads Before execute Currently executing threads: 0 get keep alive time: 0 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 : 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
|