java - ThreadPoolExecutor - Core and maximum pool sizes -


1) when new task submitted in method execute(java.lang.runnable),and fewer corepoolsize threads running,a new thread created handle request,even if other worker threads idle. why there need create new thread handle request if there idle threads?

2) if there more corepoolsize less maximumpoolsize threads running, new thread created if queue full. don't understand difference between corepoolsize , maximumpoolsize here. secondly, how can queue full when threads less maximumpoolsize? queue can full if threads equal or more maximumpoolsize. isn't it?

here sun’s rules thread creation in simple terms:

  1. if number of threads less corepoolsize, create new thread run new task.
  2. if number of threads equal (or greater than) corepoolsize, put task queue.
  3. if queue full, , number of threads less maxpoolsize, create new thread run tasks in.
  4. if queue full, , number of threads greater or equal maxpoolsize, reject task.

full article


Comments