Threads per Processor

concurrency, java

Solution

Runtime.availableProcessors returns the number of logical processors (i.e. hardware threads) not physical cores. See CR 5048379.

Problem

In Java, is there a programmatic way to find out how many concurrent threads are supported by a CPU? Update To clarify, I'm not trying to hammer the CPU with threads and I am aware of Runtime.getRuntime().availableProcessors() function, which provides me part of the information I'm looking for. I want to find out if there's a way to automatically tune the size of thread pool so that: - if I'm running on a 1-year old server, I get 2 threads (1 thread per CPU x an arbitrary multiplier of 2) - if I switch to an Intel i7 quad core two years from now (which supports 2 threads per core), I get 16 threads (2 logical threads per CPU x 4 CPUs x the arbitrary multiplier of 2). - if, instead, I use a eight core Ultrasparc T2 server (which supports 8 threads per core), I get 128 threads (8 threads per CPU x 8 CPUs x the arbitrary multiplier of 2) - if I deploy the same software on a cluster of 30 different machines, potentially purchased at different years, I don't need to read the CPU specs and set configuration options for every single one of them.

Original source