surendhar_s surendhar_s - 23 days ago 7
Java Question

How many Runnable's can be added to the queue in a fixed/cached Thread Pool?

Is there practically any limit on how many number of

Runnable
's that can be added to the queue in a fixed/cached Thread Pool of say 10 worker Threads..??

In my application, I am trying to add 100000
Runnable
's.

for (int i=0; i<100000; i++) {
executor.execute(new Task(i));
}


Will it actually process all the
Runnable
's added to the Queue..? Or will it throw an
Exception
?

Answer

Maximum number of Runnable's that can be added to the Queue in fixed/cached Thread Pool is decided by the memory allocated to the JVM.

Once all of the memory is consumed, JVM will throw

Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread

error message.