I'm struggling with something stupidly simple...
My real project was suffering of an unknown problem for ages, them i decided to create a very simple test and i got scared with the results...
Here is the test:
ExecutorService t = new ThreadPoolExecutor(10, 20, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(600));
for (int i = 0; i < 100; i++) {
final int i1 = i;
t.execute(new Runnable() {
@Override
public void run() {
while (true) {
System.out.println(i1);
try {
Thread.sleep(5000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
I'm creating a thread pool with 10 core thread plus 20 maximumPoolSize
then i give to it 100 threads which will simple print a fixed number each...
MY HUMBLE STUPID THOUGHT WAS:
The pool has 10 threads, will print 0-9 randomly then after some instans 10 extra threads will be created and pool will print from 0-19 randomly
This is kind of obvious to me since maxSize is 20 it should accept 20 tasks in worst case...
but the result was 0-9 being printed forever
the question is: What is the point of maximumPoolSize
if the extra threads are never scheduled for execution?