0
votes

Here are Sun's rules for thread creation in simple terms:

  1. If the number of threads is less than the corePoolSize, create a new Thread to run a new task.
  2. If the number of threads is equal (or greater than) the corePoolSize, put the task into the queue.
  3. If the queue is full, and the number of threads is less than the maxPoolSize, create a new thread to run tasks in.
  4. If the queue is full, and the number of threads is greater than or equal to maxPoolSize, reject the task.

Why create non-core-thread when queue is full? I don't see why they have done it this way. Why not create a non-core-thread when queue is empty?

1
If the queue is empty, what is the new thread going to run?VGR

1 Answers

-1
votes

Why create non-core-thread when queue is full?

If the queue is not full, the core threads are able to meet the demand for service. They don't need help from extra threads, so the system should not create extra threads.

If the queue fills up, that's a sign that the core threads are not enough to handle the incoming requests. The thread pool tries to alleviate the situation by creating new threads.