Runtime
Get number of processors with Runtime
In this example we shall show you how to get the number of processors with Runtime class. Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method. An application cannot create its own instance of this class. To get the number of processors with Runtime class one should perform the following steps:
- Use
getRuntime()
API method of Runtime. This method returns the runtime object associated with the current Java application. - Use
availableProcessors()
API method of Runtime. This method returns the number of processors available to the Java virtual machine.,
as described in the code snippet below.
package com.javacodegeeks.snippets.core; public class GetNumberOfProcessorsWithRuntime { public static void main(String[] args) { // get the runtime object associated with the current Java application Runtime runtime = Runtime.getRuntime(); // get the number of processors available to the Java virtual machine int numberOfProcessors = runtime.availableProcessors(); System.out.println("Number of processors available to this JVM: " + numberOfProcessors); } }
This was an example of how to get the number of processors with Runtime class in Java.
hi… first of all thanks for this post
How can I print Hello World from every processors?