Java ThreadPoolExecutor getCompletedTaskCount() MethodThe getCompletedTaskCount() of ThreadPoolExecutor is used to calculate the total number of tasks that have been completed. We can only approximate the number of tasks because the states of threads and tasks may change dynamically. The number of tasks returned by this method does not ever decrease across successive calls. SyntaxParametersNA ReturnThe number of tasks ThrowNA Example 1Test it NowOutput: Completed task count : 0 Running Thread Name: pool-1-thread-1 Running Thread Name: pool-1-thread-2 Completed Thread Name: pool-1-thread-1 Completed Thread Name: pool-1-thread-2 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 xf now i > 5 :
Next TopicJava ThreadPoolExecutor
|