Hello Friends,
In this post we will talk and learn about How to get number of available processors in Java ?
- To get the number of available processors we can use the availableProcessors() method from java.lang.Runtime Class.
- This method usually returns the number of processors which are available to the Java virtual machine.
- Once thing you should note that this number may vary during a particular call of the virtual machine.
Below is the source code for same:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
package com.kkjavatutorials.client; /** * How to get number of available processors in Java ? * @author KK JavaTutorials * */ public class ClientTest { public static void main(String[] args) { int availableProcessors = Runtime.getRuntime().availableProcessors(); System.out.print("Total available processors are: "+availableProcessors); } } |
Output of above program:
Total available processors are: 12
NOTE:You should note that output of above program may Vary machine to machine
That’s all about How to get number of available processors in Java ?
You May Also Like:
Which data type would you choose for storing currency values like Trading Price in Java?
How would you print a given currency value for Indian Locale (INR Currency)?
Which classes in java are immutable ?
How would you round a double value to certain decimal Precision and Scale ?
What is BlockingQueue? How can we implement Producer and Consumer problem using Blocking Queue?
If you have any feedback or suggestion please feel free to drop in below comment box.