Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

processors count

Posted on 2013-05-29
7
264 Views
Last Modified: 2013-06-11
hi guys

I am trying to find out how many processors i have in my Production server. i am using this code
Runtime.getRuntime().availableProcessors();

but does that give a correct count of the number of processors?

What if i have 2 boxes in a cluster and each box has one processor, will the
above code return me correct number of processors.

thanks
0
Comment
Question by:royjayd
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39205225
What hardware/software would you have that would allow clustering of processors?
0
 
LVL 16

Expert Comment

by:Valeri
ID: 39206844
No. I think you mean "nodes" when you write "boxes" in the cluster?! Am I right?
If this is the case then "Runtime.getRuntime().availableProcessors();" will be executed on each one of the boxes, because each box runs it's own JVM.
Btw Runtime.getRuntime().availableProcessors(); returns number of the cores of the processor, in your case if you have 1 processor with 4 cores, the returnd value will be "4".
0
 

Author Comment

by:royjayd
ID: 39207627
well the problem is i asked my system admin how many CPUs we are using in Production environment and he says 4
but my java code  
>>Runtime.getRuntime().availableProcessors();

returns 1

so i am not sure why there is a mismatch.
However one thing i am pretty sure is it is a production box and it cannot have just one cpu.
so as per my system admin 4 cpus sounds about right.

Thx.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 39208126
What OS are you using?
0
 

Author Comment

by:royjayd
ID: 39208138
Linux OS on production box , no application servers.
Its just a single java program running in one single jvm.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 325 total points
ID: 39208220
cat /proc/cpuinfo

Open in new window

Would be worth trying. Java uses

sysconf(_SC_NPROCESSORS_CONF)

Open in new window


http://www.gnu.org/software/libc/manual/html_node/Processor-Resources.html

You might also need to look at ulimit and quota
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39239616
:)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 45
servlet  URL Rewriting 1 42
Is Applet the way to go for my drag and drop system? 8 25
Setup GlassFish 4 21
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question