I’m using gradle tooling API to run a gradle task. When i fire 100 parallel threads. It is producing 100 daemons. Now i want to restrict the maximum no.of gradle daemons . At any point of time i need only 20 gradle daemon. when all the 20 daemons are occupied. Others should wait till gradle daemon become free. Is there any way to achieve this?
If you only want 20 to run in parallel, why do you want 100 threads? Could you just limit the number of threads you create?
To address your actual question, I’m not aware of any options to limit the number. Daemon management has been something I’ve struggled with too (primarily from having a bunch of daemons with different versions created).
We are working on a Deployment Tool which creates setups, where each setup has set of services. Each service owns, deploy.gradle which tells details about service like from where we need to checkout service assets and where to copy etc…
Before proceeding to deployment of service, we execute deploy.gradle of that service. So if we create multiple setups (say 5, parallelly) with each setup is having around 20 services which means tool invokes 100 deploy.gradle files for all setups which inherently creating 100 gradle daemons which we want to avoid. We need pool of daemon threads (say 20, will be good if it is configurable) which will be reused for other service’s deploy.gradle whenever they are free.
I’m curious as to why you can’t do the throttling on your side? That seems like a better option than having so many processes just sitting waiting for resources, that may timeout while waiting.