tags:

views:

31

answers:

1

In Java, how can I determine the system architecture of the host at run-time? With my current setup, Windows 7 x64, Java JRE 32-bit, Intel Xeon w/ Intel 64, the system properties that seem most obvious reflect the architecture of the Java VM.

System.getProperty("os.arch");
System.getProperty("sun.arch.data.model");

Result:

x86

32

A: 

You can access the OperatingSystemMXBean by calling ManagementFactory.getOperatingSystemMXBean() and it will give you:

String getName() Returns the operating system name. This method is equivalent to System.getProperty("os.name").

String getArch() Returns the operating system architecture. This method is equivalent to System.getProperty("os.arch").

String getVersion() Returns the operating system version. This method is equivalent to System.getProperty("os.version").

int getAvailableProcessors() Returns the number of processors available to the Java virtual machine. This method is equivalent to the Runtime.availableProcessors() method.

double getSystemLoadAverage() Returns the system load average for the last minute. The system load average is the sum of the number of runnable entities queued to the available processors and the number of runnable entities running on the available processors averaged over a period of time. The way in which the load average is calculated is operating system specific but is typically a damped time-dependent average. If the load average is not available, a negative value is returned.

See this page for some more details on available options. In addition most containers have more available options regarding the container.

Romain Hippeau
How is this supposed to help the poster?
jarnbjo
@jarnbjo Ism't the host asking how to find information on the underlying OS at runtime ? Then this answers the info you can get from the JVM in a portable manner. Could you explain what is wrong with the answer, or what I did not understand ?
Romain Hippeau