Processor count

In this chapter you will learn:

  1. How to get the number of processors available to the Java virtual machine

Processor count

int availableProcessors() from Runtime class returns the number of processors available to the Java virtual machine.

public class Main {
  public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();
//ja v  a 2  s  .  c  o  m
    System.out.println(runtime.availableProcessors());
  }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. How to execute a system command
  2. How to get and set working directory
Home » Java Tutorial » Utility Classes
Java standard stream
Java system property get and set
Current time in millis second and nano second
Random UUID
JVM memory
JVM garbage collector
JVM shutting down
Processor count
OS system commands
Random class
Random value
Random value range
Compile Java source code
Timer and TimerTask