Find the Number of Processors Available

Find the Number of Processors Available

There are abundant resources available in the java.lang package. Learn more about the server/host on which you are working.

The Runtime class has numerous functionalities. To learn the number of processors that are available, we can use the following:

public class CPUsCount{public static void main(String args[]){CPUsCount cPUsCount = new CPUsCount();cPUsCount.proceed();}private void proceed(){//Returns the count of processors in the host that this application is runSystem.out.println("Availabe processor count: " + Runtime.getRuntime().availableProcessors());}}

Expected output:

[root@mypc]# java CPUsCountAvailabe processor count: 4
See also  Java Developer Jobs: Your Guide to Landing the Perfect Position in 2024

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist