multithreading - Removing idle threads from thread pool in Java? -
i'm using java thread pool of fixed size (executorservice). let's assume submit job thread pool , job gets idle.
is there possibility idle jobs removed thread pool, other jobs queue can processed , idle job later added again?
if move executorservice
threadpoolexecutor, can achieve below api
public void setcorepoolsize(int corepoolsize)
sets core number of threads. overrides value set in constructor. if new value smaller current value, excess existing threads terminated when next become idle.
if larger, new threads will, if needed, started execute queued tasks.
if want re-size pool @ run time,
((threadpoolexecutor)service).setcorepoolsize(newlimit);
//newlimit new size of pool
other api:
public void setmaximumpoolsize(int maximumpoolsize)
sets maximum allowed number of threads. overrides value set in constructor. if new value smaller current value, excess existing threads terminated when next become idle.
Comments
Post a Comment