Javatpoint Logo
Javatpoint Logo

Java ThredPoolExecutor getKeepAliveTime() Method

The 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.

Syntax

Parameters

unit - the desired time unit of the result

Return

the time limit

Throw

Does not throw exception.

Example 1

Test it Now

Output:

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 2

Test it Now

Output:

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 :






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