如何查看JVM的系统属性
晚上闲来没事,突发奇想,每次想查看系统属性的时候都要去写个jsp去获取指定key的属性的值。既然我们经常用到,干嘛不写个独立页面,单独查看JVM的系统属性呢?反正不也不是很复杂,那就动手干吧。
一、 原理简介
我们获取jvm系统属性的时候,我们都是通过
System.getProperty(“paramName”),当我们再仔细看下System对象的时候,我们发现还有个getProperties方法。阅读下说明,果然是返回当前JVM的系统属性。
二、 编写JSP
只需要把下面内容拷贝到jsp页面中,并把该jsp放到应用中即可,具体内容如下:
<% /* 列出当前系统中的参数 */ %> <%@ page contentType="text/html;charset=UTF-8" pageEncoding="GBK" errorPage="../include/error.jsp"%> <!------- IMPORTS BEGIN ------------> <%@ page import="java.util.Properties" %> <%@ page import="java.util.Iterator" %> <%@ page import="java.util.Map" %> <%@ page import="java.util.Map.Entry" %> <!------- IMPORTS END ------------>
<!-- 页面登录信息,常量获取信息-->
<%!boolean IS_DEBUG = false;%>
<%
//1.获取参数
//2.权限判断
//3.逻辑操作 //获取当前系统的内存情况 Runtime currRuntime = Runtime.getRuntime(); currRuntime.gc(); long nTotalMemory = currRuntime.totalMemory(); long nFreeMemoy = currRuntime.freeMemory();
//把单位从字节转化为兆 String sSystemTotalMemoy = (nTotalMemory/1024/1024) + "M"; String sFreeSystemMemoy = (nFreeMemoy/1024/1024) + "M";
%>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>当前系统中的参数</title> <style> .td_bg_color{ background-color:#FFFFFF; } .td_padding_left{ padding-left:10px; } </style> </head>
<body> <table border="0" cellspacing="1" cellpadding="0" width="100%" style="background-color:#d1d6e9;"> <tr> <td colspan="3" class="td_bg_color">当前系统的中参数列表,即[System.getProperties()]获取的值为</td> </tr> <tr> <td class="td_bg_color" align="center" width="60px">序号</td> <td class="td_bg_color" align="center" width="300px">名称</td> <td class="td_bg_color" align="center">值</td> </tr> <% //打印出系统的属性值 int nIndex = 0; Properties properties = System.getProperties(); if(properties!=null){ Iterator iterator = properties.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry aEntry = (Entry) iterator.next(); if (aEntry == null) { continue; } nIndex ++; %> <tr> <td class="td_bg_color" align="center"><%=nIndex%></td> <td class="td_bg_color td_padding_left"><%=aEntry.getKey()%></td> <td class="td_bg_color td_padding_left"><%=aEntry.getValue()%></td> </tr> <% }//end while }else{//end if %> <tr> <td class="td_bg_color" colspan="3" align="right"> <span style="margin-right:20px;">当前系统对象[System]中没有属性.</span> </td> </tr> <% }//end else %> <tr> <td class="td_bg_color" align="center"><%=nIndex++%></td> <td class="td_bg_color td_padding_left">总共内存</td> <td class="td_bg_color td_padding_left"><%=sSystemTotalMemoy%></td> </tr> <tr> <td class="td_bg_color" align="center"><%=nIndex++%></td> <td class="td_bg_color td_padding_left">空闲内存</td> <td class="td_bg_color td_padding_left"><%=sFreeSystemMemoy%></td> </tr> </table> </body> </html> |
三、 访问页面结果
访问上边内容所在的页面,页面展现结果如下,是不是可以很方便的找到当前JVM的属性值了。如果要查找某个指定名称的值,只需要利用浏览器提供的查找(ctrl+F)功能即可。是不是方便了很多,访问页面结果如下:
|
|