/**
* Gets the number of cores available in this device, across all processors.
* Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
* @return The number of cores, or 1 if failed to get result
*/privateint getNumCores(){//Private Class to display only CPU devices in the directory listingclassCpuFilterimplementsFileFilter{@Overridepublicboolean accept(File pathname){//Check if filename is "cpu", followed by a single digit numberif(Pattern.matches("cpu[0-9]", pathname.getName())){returntrue;}returnfalse;}}try{//Get directory containing CPU infoFile dir =newFile("/sys/devices/system/cpu/");//Filter to only list the devices we care aboutFile[] files = dir.listFiles(newCpuFilter());//Return the number of cores (virtual CPU devices)return files.length;}catch(Exception e){//Default to return 1 corereturn1;}}