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 configure servlets in web.xml? - April 19, 2025
- How do I handle cookies using Jakarta Servlet API? - April 19, 2025
- How do I set response headers with HttpServletResponse? - April 18, 2025