dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Find the Number of Processors Available

There are abundant resources available in the java.lang package. Learn more about how to figure out the number of processors that are available.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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 run
System.out.println("Availabe processor count: " + Runtime.getRuntime().availableProcessors());

}
}

Expected output:

[root@mypc]# java CPUsCount
Availabe processor count: 4

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date