dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Sep 6, 2019

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

}
}

Expected output:

[root@mypc]# java CPUsCount
Availabe processor count: 4
Sridhar M S
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date