How to Get Processors Available in Java


This example aims to get number of processors available to current Java Virtual Machine (JVM).

Source Code

package com.beginner.examples;

public class GetProcessorsExample {

    public static void main(String[] args){
    	
    	Runtime run = Runtime.getRuntime();
    	// get available processors
		int num = run.availableProcessors();		 
		System.out.println(num + " processors are available to JVM.");
    }
    
}

Output:

4 processors are available to JVM.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments