Android 内核数量

262 阅读1分钟
  1. 获取当前cpu的内核数量: Runtime.getRuntime().availableProcessors();

  2. 获取当前的cpu可用的core数: //获取CPU内核数 public int getCPUCoreCount() { class CpuFilter implements FileFilter { @Override public boolean accept(File pathname) { if(Pattern.matches("cpu[0-9]", pathname.getName())) { return true; } return false; }
    }

     try {
         File dir = new File("/sys/devices/system/cpu/");
         File[] files = dir.listFiles(new CpuFilter());
         return files.length;
     } catch(Exception e) {
         Log.d(TAG, "CPU Count: Failed.");
         e.printStackTrace();
         return 1;
     }
    

    }