求赐教
------解决方案--------------------
《JAVA并发编程实践》
------解决方案--------------------
Java并发编程实战
机械工业出版社~
------解决方案--------------------
深入理解JAVA虚拟机
------解决方案--------------------
java获取系统信息(CPU,内存,硬盘,进程)的相关方法
- Java code
import java.io.*;import com.sun.management.OperatingSystemMXBean;import sun.management.ManagementFactory;public class Tst{ public static String pt="D:\\abc.txt"; public Tst(){ } public static void main(String[] args) throws Exception{ //free和use和total均为KB long free=0; long use=0; long total=0; int kb=1024; Runtime rt=Runtime.getRuntime(); total=rt.totalMemory(); free=rt.freeMemory(); use=total-free; System.out.println("系统内存已用的空间为:"+use/kb+" MB"); System.out.println("系统内存的空闲空间为:"+free/kb+" MB"); System.out.println("系统总内存空间为:"+total/kb+" MB"); OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long physicalFree=osmxb.getFreePhysicalMemorySize()/kb; long physicalTotal=osmxb.getTotalPhysicalMemorySize()/kb; long physicalUse=physicalTotal-physicalFree; String os=System.getProperty("os.name"); System.out.println("操作系统的版本:"+os); System.out.println("系统物理内存已用的空间为:"+physicalFree+" MB"); System.out.println("系统物理内存的空闲空间为:"+physicalUse+" MB"); System.out.println("总物理内存:"+physicalTotal+" MB"); // 获得线程总数 ThreadGroup parentThread; for (parentThread = Thread.currentThread().getThreadGroup(); parentThread .getParent() != null; parentThread = parentThread.getParent()) ; int totalThread = parentThread.activeCount(); System.out.println("获得线程总数:"+totalThread); } }