Javatpoint Logo
Javatpoint Logo

Java ThreadPoolExecutor getTaskCount() Method

The getTaskCount() returns the approximate total number of tasks that have ever been scheduled for the execution. Because, the states of tasks and threads may change dynamically during computation, the returned value is only an approximation.

Syntax

Parameters

No parameter is passed.

Return

The number of tasks

Throw

Does not throw the exception.

Example 1

Test it Now

Output:

get Task count before:1
get Task count after:2
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 2

Test it Now

Output:

Starting threads
  Maximum pool size: 2147483647
get Task count before:0
Thread sleeping for 1000 i=0
Thread sleeping for 1000 i=0
Thread sleeping for 1000 i=0
get Task count after:4
Threads started, main ends

Thread sleeping for 1000 i=0
Thread sleeping for 1000 i=1
Thread sleeping for 1000 i=1
Thread sleeping for 1000 i=1
Thread sleeping for 1000 i=1
Thread sleeping for 1000 i=2
Thread sleeping for 1000 i=2
Thread sleeping for 1000 i=2
Thread sleeping for 1000 i=2
Thread sleeping for 1000 i=3
Thread sleeping for 1000 i=3
Thread sleeping for 1000 i=3
Thread sleeping for 1000 i=3
Thread sleeping for 1000 i=4
Thread sleeping for 1000 i=4
Thread sleeping for 1000 i=4
Thread sleeping for 1000 i=4
 now  i > 5 :
 now  i > 5 :
 now  i > 5 :
 now  i > 5 :






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA