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