What is ArchUtils.getProcessor() in Java?
getProcessor is a static method of the ArchUtils class that is used to get an instance of the Processor class for the value of the system property os.arch.
The
os.archsystem property returns the architecture used by the JVM, not of the operating system.
There are two variations of the method. They are described below.
Variation 1
This variation returns a Processor object of the current JVM.
Syntax
public static Processor getProcessor()
Parameters
The method has no parameters.
Variation 2
This variation returns a Processor object for the given value string. The string value must be like a value returned by the os.arch system property.
Syntax
public static Processor getProcessor(final String value)
Parameters
final String value: A string like a value returned by theos.archsystem property.
Return value
An instance of the Processor class is returned in both the variations.
How to import ArchUtils
The definition of ArchUtils can be found in the Apache Commons Lang package, which we can add to the Maven project by adding the following dependency to the pom.xml file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the
commons-langpackage, refer to the Maven Repository.
You can import the ArchUtils class as follows:
import org.apache.commons.lang3.ArchUtils;
Code
import org.apache.commons.lang3.ArchUtils;import org.apache.commons.lang3.arch.Processor;public class Main{public static void main(String[] args){// Example 1Processor processor = ArchUtils.getProcessor();System.out.printf("The current JVM architecture is - Processor(%s, %s)", processor.getArch(), processor.getType());System.out.println();// Example 2String archValue = "ia64_32";processor = ArchUtils.getProcessor(archValue);System.out.printf("The Processor object for %s is - Processor(%s, %s)", archValue, processor.getArch(), processor.getType());}}
Output
The current JVM architecture is - Processor(BIT_64, X86)
The Processor object for ia64_32 is - Processor(BIT_32, IA_64)
Example 1
In the first example, we print the current JVM architecture to the console.
Example 2
In the second example, we get the processor object for the given ia64_32 architecture value. The method returns a processor object that has BIT_32 as the bit architecture and IA_64 as the type of processor.
Free Resources
- undefined by undefined