I need to get the number of avaible CPU threads on a machine.
Previously I used Runtime.getRuntime().availableProcessors()
to determine that and it works just fine for my PC at home. It returns 16
in my case (cause I got a 8 core, 16 thread processor).
Now I wanted to use that application on a server that has a dual socket configuration, two Xeon Gold 6154 with 18 cores/36 threads each. The way I used to determine the amount of threads now gives me 36
instead of 72
.
It seems like the avaibleProcessors()
method does not respect dual socket configurations.
What I found with some research is java.util.concurrent.ForkJoinPool.commonPool()
, that should work with dualsocket configurations. However, on my local PC it returns java.util.concurrent.ForkJoinPool@61e717c2[Running, parallelism = 15, size = 0, active = 0, running = 0, steals = 0, tasks = 0, submissions = 0]
aka one thread is missing... Is that normal? Do I have to do some math and add 1 to the number? The output is not that well formatted either, I would have to do some Regex or similar to get that to a usable format.
Are there better ways to determine the amount of threads on a machine? Or do I have to stick with the commonPool() method for now?