memory.jsp 926 B

1234567891011121314151617181920212223
  1. <%@ page import="java.text.DecimalFormat" %>
  2. <%@page contentType="text/html" pageEncoding="UTF-8" %>
  3. <!DOCTYPE>
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>JVM memory</title>
  8. </head>
  9. <body>
  10. <%
  11. final double mb = 1024.0 * 1024;
  12. final Runtime runtime = Runtime.getRuntime();
  13. double total = (runtime.totalMemory()) / mb;
  14. double max = (runtime.maxMemory()) / mb;
  15. double free = (runtime.freeMemory()) / mb;
  16. DecimalFormat format = new DecimalFormat("0.##");
  17. out.println("当前JVM的最大可用内存(maxMemory): " + format.format(max) + "MB<br/>");
  18. out.println("当前JVM占用的内存总数(totalMemory): " + format.format(total) + "MB<br/>");
  19. out.println("当前JVM空闲内存(freeMemory): " + format.format(free) + "MB<br/>");
  20. out.println("JVM实际可用内存: " + format.format(max - total + free) + "MB<br/>");
  21. %>
  22. </body>
  23. </html>