Home Java Java-get-example Java get number of Processors



Java get number of Processors
Posted on: November 1, 2008 at 12:00 AM
In this section, we are going to obtain the number of processors available in Java Virtual Machine.

Java get number of Processors

     

In this section, we are going to obtain the number of processors available in Java Virtual Machine.

To display the number of processors available to a current Java Virtual Machine, we have used the method availableProcessors() of class Runtime and the method getRuntime() returns the instance of Runtime class with the java application.

Here is the code GetProcessors.java

public class GetProcessors {
    
    public void displayAvailableProcessors() {
      Runtime runtime = Runtime.getRuntime();
      int numberOfProcessors = runtime.availableProcessors();
      System.out.println("Number of processors available to the Java Virtual Machine: " 
                 + numberOfProcessors);
      }
    public static void main(String[] args) {
    new GetProcessors().displayAvailableProcessors();
    }
}

Output will be displayed as:

Download Source Code

Related Tags for Java get number of Processors:
javacmacprocessiovirtualvinumberthisssoaiprocessortoproceilsectionmachineceinmjesprossoessprocessorsisirgoarrtvassrocthavchiabablprocesprono


More Tutorials from this section

Ask Questions?    Discuss: Java get number of Processors  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.