javaconcurrencyexecutorserviceexecutors

Existing ForkJoinPool or ExecutorService?


I have a silly problem, I need an ExecutorService (and ForkJoinPool is such a thing) but I don't really want to initialise a new one and keep that reference, I remember a while back running into a JDK class that maintained an static ForkJoinPool for various uses and that could be used by other processes, but I can't seem to find it and there is not that much info about such a thing online. Does any know if such a thing exists ?


Solution

  • ForkJoinPool.commonPool() is a single, static instance

    You can use Executors.newWorkStealingPool to get a work stealing pool (which uses ForkJoinPool.defaultForkJoinWorkerThreadFactory under the hood), but that would require you to store the pool reference.

    Both of these will therefore be per-JVM (per-process), not cross-process as you say you need, I don't know of a pool you can use to do that.