---
title: CPU架构
description: "- 方法一："
url: https://www.hikunpeng.com/document/detail/zh/kunpenggrf/codeprtr/kunpengtaishanporting_12_0067.html
sourcePath: /source/zh/kunpenggrf/codeprtr/kunpengtaishanporting_12_0067.html
indexId: d173e18310fda1d5301f9414f24fac02d88775b1db96f1fa3d16c72f7f92cd9165
---
# CPU架构

- 方法一：
  使用System.getProperty方法可以获取系统相关属性，CPU架构类型可用System.getProperty("os.arch")

  示例：

```
public class SystemProperty {
public static void main(String args[]) {
System.out.println("os_name:" + System.getProperty("os.name"));
System.out.println("os_arch:" + System.getProperty("os.arch"));
}
}
```


  鲲鹏上执行结果：

```
[root@centos7 test]# java SystemProperty
os_name:Linux
os_arch:aarch64
```


- 方法二：
  调用ManagementFactory.getOperatingSystemMXBean()方法获取。

  代码示例：

```
import Java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
public class SystemProperty {
public static void main(String args[]) {
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementF
actory.getOperatingSystemMXBean();
String osArch = osmxb.getArch();
System.out.println("osArch: " + osArch);
}
}
```


  鲲鹏上执行结果：

```
[root@centos7 test]# java SystemProperty
osArch: aarch64
```
