What's the recommended corePoolSize passed to ThreadPoolExecutor/ScheduledThreadPoolExecutor?
Runtime.getRuntime().availableProcessors()
?
Runtime.getRuntime().availableProcessors() * 2
?
From one point, I'd like the CPU (all the cores) to be utilized 100% but as little threads to do it as possible, in order for them to finish as quickly as possible and not have too much penalty on context switching.
On the other hand, some of the threads might not utilize the CPU all the time, like waiting for network. In that case, I'd like new threads to be spawned and keep all the cores busy.
I'm OK if there's a temporary over-usage of the CPU. Better than under-usage and tasks not being handled.
So how can I achieve this thread load balance? Thanks.