Java Host Architecture Architecture

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

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

Result:

x 86

32

+3
source share
3 answers

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

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

getArch() . System.getProperty( "os.arch" ).

getVersion() . System.getProperty( "os.version" ).

int getAvailableProcessors() , Java. Runtime.availableProcessors().

double getSystemLoadAverage() . , , , , . , , , . , .

. . , .

+1

Windows, Windows . Linux/Solaris, , .

, ...

IMPORTANT: Fallback for ANY problem/exception, return "os.arch"
1) Check if System.getProperty("os.name") doesn't contain Windows
2) Exec "uname -p", capture the output
0

sun.cpu.isalist . , Windows 64- JRE, "amd64". , 32 JRE : "pentium_pro + mmx pentium_pro pentium + mmx pentium i486 i386 i86"

Windows 7 x64, Intel I7 JRE 1.6 (32 64 ).

0

Source: https://habr.com/ru/post/1759211/


All Articles