?
Solved

processors count

Posted on 2013-05-29
7
Medium Priority
?
268 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 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