Where can I find the soruce code/implementation for the availableProcessors()
method in the java.lang.Runtime
class.

- 377
- 1
- 3
- 13
-
most likely it's a native function. Are you interested in the C implementation? – John Dvorak Oct 09 '13 at 06:29
-
3Possible duplicate http://stackoverflow.com/questions/12594046/java-native-method-source-code @Abhilash you'll find your answer there – Alowaniak Oct 09 '13 at 06:31
-
The method getAvailableProcessors is not part of Runtime class. – Juned Ahsan Oct 09 '13 at 06:31
-
@Abhilash you probably meant `availableProcessors()` instead – Alowaniak Oct 09 '13 at 06:33
1 Answers
Since it's a bit hard to find but the source code is here: http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/runtime/os.cpp
Look for os::_processor_count
The value is set in a OS-specific file. Here is the Linux version.
My strategy to find this was: Google for site:http://hg.openjdk.java.net/ jdk7 runtime
Then I opened the first link (http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/runtime/synchronizer.cpp) and removed the synchronizer.cpp
from the URL. I can now see all the files in the runtime/
folder. Then I went through the file names. os.cpp
sounded interesting.
For the link above, I replaced the revision number with tip
to make the link always point to the latest version.
Inside of that file, I saw os::_processor_count
.
Googling for that gave me a couple of links again. os_linux.cpp
looked promising.

- 321,842
- 108
- 597
- 820