1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| * 获得Tomcat的内存信息 * @return */ private Map<String, Object> getMemoryInfo() { Map<String, Object> memDataMap = new HashMap<String, Object>();
double MB = 1024.0 * 1024.0;
double maxMemory = (Runtime.getRuntime().maxMemory()) / MB;
double totalMemory = (Runtime.getRuntime().totalMemory()) / MB;
double freeMemory = (Runtime.getRuntime().freeMemory()) / MB;
double totalUsableMemory = maxMemory - totalMemory + freeMemory;
memDataMap.put("totalUsableMemory", totalUsableMemory); memDataMap.put("totalMemory", totalMemory); memDataMap.put("maxMemory", maxMemory);
NumberFormat nt = NumberFormat.getPercentInstance(); nt.setMinimumFractionDigits(2); memDataMap.put("memUsage", nt.format(totalMemory / maxMemory));
return memDataMap; }
|