Is there some direct way in
Java to tell how many CPUs a computer has available to run threads in parallel? I took a look at class
System, but none of its methods looked like they returned that value. I wrote a couple of Java classes:
and
and I was thinking I could tell from the graph drawn how many CPUs my computer had. For example, if it had four then the time for four threads to all complete would be roughly a fourth of the time for just one
thread to complete the same job. Alternately, if it just had two CPUs then I would expect the time for two threads to both complete would be roughly half the time for just one thread to complete the same job, and the time for any number of threads higher than two to complete would be longer, or at least the same. But when I ran "java ThGr 8 100002 5 1300 650 1 30" I got results between those two expected results; for three threads and for four threads the job got done quicker than it did for two threads, but not by anywhere near what I expected. So how can I tell how many CPUs my computer has?