HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaCritical

Finding Number of Cores in Java

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
javacoresfindingnumber

Problem

How can I find the number of cores available to my application from within Java code?

Solution

Call Runtime#availableProcessors.

int cores = Runtime.getRuntime().availableProcessors();


If cores is less than one, either your processor is about to die, or your JVM has a serious bug in it, or the universe is about to blow up.

Code Snippets

int cores = Runtime.getRuntime().availableProcessors();

Context

Stack Overflow Q#4759570, score: 911

Revisions (0)

No revisions yet.