java運行時,環境信息獲得

<%@page import="java.util.TimeZone"%>
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Calendar" %>

<%!public Long getMaxMemory() {
	try {
		Runtime rt = Runtime.getRuntime();
		Method m = rt.getClass().getMethod("maxMemory", new Class[0]);
		Long r = (Long) m.invoke(rt, new Object[0]);
		return r;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return new Long(-1);
}
%>
<%!public Integer getAvailableProcessors() {
	try {
		Runtime rt = Runtime.getRuntime();
		Method m = rt.getClass().getMethod("availableProcessors",
				new Class[0]);
		return (Integer) m.invoke(rt, new Object[0]);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return new Integer(-1);
}
%>
<%!public String getHostName() {
	String hostName = null;
	try {
		hostName = java.net.InetAddress.getLocalHost().getHostName();
	} catch (java.net.UnknownHostException e) {
		hostName = "<unknown>";
	}
	return hostName;
}
%>
<%!public String getHostAddress() {
	String hostAddress = null;
	try {
		hostAddress = java.net.InetAddress.getLocalHost().getHostAddress();
	} catch (java.net.UnknownHostException e) {
		hostAddress = "<unknown>";
	}
	return hostAddress;
}
%>

<%!public ThreadGroup getRootThreadGroup() {
	ThreadGroup group = Thread.currentThread().getThreadGroup();
	while (group.getParent() != null) {
		group = group.getParent();
	}
	return group;
}
%>

<%!public String getTimeZoneInfo() {
	Calendar cal = Calendar.getInstance();
	TimeZone tz = cal.getTimeZone();
	String tzId = tz.getID();
	int rawOffset = tz.getRawOffset();
	
	int hourOffset = rawOffset / (1000 * 60 * 60);
	String tzInfo = "";
	if (hourOffset == 0){
		tzInfo = "中時區";
	}else{
		String dir = (hourOffset > 0) ? "東" : "西";
		tzInfo = dir + Math.abs(hourOffset) + "區";
	}
	return tzInfo + "(" + tzId + ")";
   }
%>
<HTML>
 <HEAD>
  <title>系統環境信息</title>
  <meta http-equiv="Content-Type" content="text/html; charset=GBK">
  <META NAME="Author" CONTENT="mahh">
  <META NAME="Description" CONTENT="系統環境信息">
   <style type="text/css"> 
	.version{
		border-collapse:collapse
		} 
	.version td{ 
		border:1px solid #999999
	} 
  </style>

 </HEAD>
 <BODY style="background:transparent;">
<div>
	<table class="" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
	<tr class="title_display">
	<td height="30" colspan="2"><jsp:include page="pages/title.jsp?title=系統環境信息"/></td>
	</tr>
	  <tr>
		<td class="" >
		<table class="FormUnitTable" width="100%" border="0"cellpadding="0" cellspacing="0" class="table" id="version">
		<tr>
			<th class="table_bg th_width_120 text-right table_height"   >統計時間:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >時區:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=getTimeZoneInfo()%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"   >操作系統:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("os.name")+" "+System.getProperty("os.arch")+" "+System.getProperty("os.version")%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >當前使用JAVA_HOME:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("java.home")%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >JAVA虛擬機名稱(java.vm.name):</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("java.vm.name")%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >JAVA虛擬機供應商(java.vm.vendor):</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("java.vm.vendor")%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >JAVA虛擬機版本(java.vm.version):</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("java.vm.version")%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >JAVA版本(java.version):</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("java.version")%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >JAVA版本(java.vendor):</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("java.vendor")%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height"  >JAVA虛擬機位數:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=System.getProperty("sun.arch.data.model")%></td>
		</tr>
		<!-- 
		<tr>
			<td>當前佔用內存總數</td><td><%=new Long(Runtime.getRuntime().totalMemory()).longValue()/(1024 * 1024)%>MB</td>
		</tr>
		<tr>
			<td>當前佔用內存剩餘</td><td><%=new Long(Runtime.getRuntime().freeMemory()).longValue()/(1024 * 1024)%>MB</td>
		</tr>
		<tr>
			<td>最大可佔用的內存</td><td><%=getMaxMemory().longValue() / (1024 * 1024)%>MB</td>
		</tr>
		 -->
		<tr>
			<th class="table_bg th_width_120 text-right table_height" >當前活動線程組總數:</th>
			<td width="70%" colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=new Integer(getRootThreadGroup().activeGroupCount())%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height" >當前活動線程總數:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=new Integer(getRootThreadGroup().activeCount())%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height" >CPU內核數:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=getAvailableProcessors()%></td>
		</tr>
		<tr>	
			<th class="table_bg th_width_120 text-right table_height" >當前主機IP地址:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=getHostAddress()%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height" >當前主機名稱:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;" ><%=getHostName()%></td>
		</tr>
		<tr>
			<th class="table_bg th_width_120 text-right table_height" >當前使用者瀏覽器運行模式:</th>
			<td colspan="1" rowspan="1" class="" align="left" valign="middle" nowrap="nowrap" style="padding:0 5px 0 5px;"  id="browserVersion"></td>
		</tr>
	</table>
		</td>
	  </tr>
 </table>
</div>
 </BODY>
</HTML>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章