The Runtime.getRuntime().availableProcessors()
method returns the maximum number of processors available to the Java virtual machine, the value will never be smaller than one. Knowing the number of available processor you can use it for example to limit the number of thread in your application when you are writing a multi-thread code.
package org.kodejava.lang;
public class NumberProcessorExample {
public static void main(String[] args) {
final int processors = Runtime.getRuntime().availableProcessors();
System.out.println("Number of processors = " + processors);
}
}
Running the code snippet give you something like:
Number of processors = 8
Latest posts by Wayan (see all)
- How do I create a servlet filter to make secure cookies? - April 18, 2024
- How do I configure secure cookies using web.xml? - April 18, 2024
- How do I create a table with multiple header in iText 8? - March 16, 2024