cache_jvm.jsp
上传用户:jhtang88
上传日期:2014-01-27
资源大小:28528k
文件大小:5k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ page import="java.util.*,
  3.  java.text.*"
  4. %>
  5. <jsp:useBean id="StrUtil" scope="page" class="cn.js.fan.util.StrUtil"/>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  10. <link href="../common.css" rel="stylesheet" type="text/css">
  11. <link href="default.css" rel="stylesheet" type="text/css">
  12. <title>查看java虚拟机内存</title>
  13. </head>
  14. <body>
  15. <table cellSpacing="0" cellPadding="0" width="100%">
  16.   <tbody>
  17.     <tr>
  18.       <td align="left" class="head">系统信息</td>
  19.     </tr>
  20.   </tbody>
  21. </table>
  22. <jsp:useBean id="privilege" scope="page" class="cn.js.fan.module.pvg.Privilege"/>
  23. <%
  24. if (!privilege.isUserPrivValid(request, "forum.plugin"))
  25. {
  26. out.print(cn.js.fan.web.SkinUtil.makeErrMsg(request, cn.js.fan.web.SkinUtil.LoadString(request, "pvg_invalid")));
  27. return;
  28. }
  29. %>
  30. <br>
  31. <TABLE 
  32. style="BORDER-RIGHT: #a6a398 1px solid; BORDER-TOP: #a6a398 1px solid; BORDER-LEFT: #a6a398 1px solid; BORDER-BOTTOM: #a6a398 1px solid" 
  33. cellSpacing=0 cellPadding=3 width="95%" align=center>
  34.   <!-- Table Head Start-->
  35.   <TBODY>
  36.     <TR>
  37.       <TD width="70%" align="left" noWrap class=thead style="PADDING-LEFT: 10px"><font size="-1"><b>Java VM (Java虚拟机)内存</b></font> </TD>
  38.     </TR>
  39.     <TR class=row style="BACKGROUND-COLOR: #fafafa">
  40.       <TD height="175" align="center" style="PADDING-LEFT: 10px"><p>
  41.           <p>
  42.             <%!
  43. static final DecimalFormat mbFormat = new DecimalFormat("#0.00");
  44. static final DecimalFormat percentFormat = new DecimalFormat("#0.0");
  45.     static final int NUM_BLOCKS = 50;
  46. %>
  47.             <%
  48. String op = request.getParameter("op");
  49. if (op==null)
  50. op = "";
  51. // The java runtime
  52. Runtime runtime = Runtime.getRuntime();
  53. if (op.equals("gc")) {
  54. runtime.gc();
  55. out.println("<p><font size=-1 color=red>&nbsp;&nbsp;&nbsp;垃圾已收集</font></p>");
  56. }
  57.     double freeMemory = (double)runtime.freeMemory()/(1024*1024);
  58. double totalMemory = (double)runtime.totalMemory()/(1024*1024);
  59. double maxMemory = Runtime.getRuntime().maxMemory()/(1024*1024);
  60. double usedMemory = totalMemory - freeMemory;
  61. double percentFree = ((double)freeMemory/(double)totalMemory)*100.0;
  62.     int free = 100-(int)Math.round(percentFree);
  63. %>
  64.         <ul><table width="277" border=0>
  65.             <tr>
  66.               <td width="135"><font size="-1">已用内存:</font></td>
  67.               <td width="132"><font size="-1"><%= mbFormat.format(usedMemory) %> MB</font></td>
  68.             </tr>
  69.             <tr>
  70.               <td><font size="-1">内存总量:</font></td>
  71.               <td><font size="-1"><%= mbFormat.format(totalMemory) %> MB</font></td>
  72.             </tr>
  73.             <tr>
  74.               <td><font size="-1">最大内存</font></td>
  75.               <td><font size="-1"><%= mbFormat.format(maxMemory) %> MB</font></td>
  76.             </tr>
  77.             <tr>
  78.               <td><font size="-1">处理器数</font></td>
  79.               <td><font size="-1"><%=runtime.availableProcessors()%> 个</font></td>
  80.             </tr>
  81.             </table>
  82.           <br>
  83.           <table border=0>
  84.             <td><table bgcolor="#000000" cellpadding="1" cellspacing="0" border="0" width="200" align=left>
  85.           <td><table bgcolor="#000000" cellpadding="1" cellspacing="1" border="0" width="100%">
  86.                 <%    for (int i=0; i<NUM_BLOCKS; i++) {
  87.         if ((i*(100/NUM_BLOCKS)) < free) {
  88.     %>
  89.                 <td bgcolor="#00ff00" width="<%= (100/NUM_BLOCKS) %>%"><img src="images/blank.gif" width="1" height="15" border="0"></td>
  90.                     <% } else { %>
  91.                     <td bgcolor="#006600" width="<%= (100/NUM_BLOCKS) %>%"><img src="images/blank.gif" width="1" height="15" border="0"></td>
  92.                     <% }
  93.     }
  94. %>
  95.             </table></td>
  96.               </table></td>
  97.                 <td><font size="-1"> &nbsp;<b><%= percentFormat.format(percentFree) %>% 空闲</b> </font> </td>
  98.           </table>
  99.           <br>
  100.           <table width="200"  border="0" cellspacing="0" cellpadding="0">
  101.             <tr>
  102.               <td align="center">>>&nbsp;<font size="-1"><a href="cache_jvm.jsp?op=gc">垃圾收集</a></font>&nbsp;&nbsp; <font size="-1"><a href="cache_jvm.jsp">刷新</a></font>&nbsp;<<</td>
  103.             </tr>
  104.             <tr>
  105.               <td height="48" align="center"><font size="-1">注意垃圾收集器是低线程级的,不能被强制执行</font></td>
  106.             </tr>
  107.             </table>
  108.           </ul>
  109.           <% // Destroy the runtime reference
  110. runtime = null;
  111. %>
  112. </TD>
  113.     </TR>
  114.     <!-- Table Body End -->
  115.     <!-- Table Foot -->
  116.     <TR>
  117.       <TD class=tfoot align=right><DIV align=right> </DIV></TD>
  118.     </TR>
  119.     <!-- Table Foot -->
  120.   </TBODY>
  121. </TABLE>
  122. <p>
  123. </body>
  124. </html>