Finding Number of Cores in Java

Submitted 4 years, 6 months ago
Ticket #250
Views 376
Language/Framework Java
Priority Low
Status Closed

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

Submitted on Oct 19, 20
add a comment

1 Answer

Verified

The java.lang.Runtime.availableProcessors() method returns the number of processors available to the Java virtual machine.This value may change during a  Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the 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.

Submitted 4 years, 6 months ago


Latest Blogs