Java ThreadPoolExecutor getActiveCount() MethodThe getActiveCount() method of ThreadPoolExecutor class returns the approximate number of threads that are actively executing the tasks. SyntaxParametersNA ReturnsThe number of threads ThrowDoes not throw the exception. Example 1Test it NowOutput: Currently executing threads: 0 Running Thread Name: pool-1-thread-2 Running Thread Name: pool-1-thread-1 Completed Thread Name: pool-1-thread-1 Completed Thread Name: pool-1-thread-2 Example 2Test it NowOutput: Starting threads Before execute Currently executing threads: 0 After execute Currently executing threads: 1 Thread sleeping for 1000 i=0 Threads started, main ends 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
|