Possible result: more threads will be launched at the same time, because newCachedThreadPool () allows you to start Integer.MAX_VALUE threads.
Itβs impossible to guess how to influence you without looking at your code.
But, as I think, if the problem is solved by increasing the number of threads, there is a high probability that you have locks.
For example, you have 4 resources A, B, C, D. And 4 tasks:
1) short TaskA requires resource A
2) short TaskB requires resource B
3) short TaskC requires resource C
4) long TaskD requires resources A and D
So, at one point in time, we will have the following situation:
Thread1: TaskA await for resource A Thread2: TaskD has A and D and running TaskB wait in Queue TaskC wait in Queue
When you change pull to pull with an unlimited number of threads, or a fixed thread pool with many allowed threads:
Thread1: TaskA await for resource A Thread2: TaskD has A and D and running Thread3: TaskB has resource B Thread4: TaskC has resource C
So, one of the threads is blocked by the other, but you cannot see it, because all other tasks are performed without locks.
source share