Skip to content

Instantly share code, notes, and snippets.

@qsLI
Created June 6, 2018 03:54
Show Gist options
  • Save qsLI/bd80dc3b2abb82ac778a9403bde62bf5 to your computer and use it in GitHub Desktop.
Save qsLI/bd80dc3b2abb82ac778a9403bde62bf5 to your computer and use it in GitHub Desktop.
get directmemory usage
<%@ page import="java.lang.management.BufferPoolMXBean" %>
<%@ page import="java.util.List" %>
<%@ page import="java.lang.management.ManagementFactory" %><%--
Created by IntelliJ IDEA.
User: qishengli
Date: 18-6-6
Time: 上午11:40
To change this template use File | Settings | File Templates.
--%>
<%
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean pool : pools) {
out.write("<BR>name: " + pool.getName());
out.write("<BR>count: " + pool.getCount());
out.write("<BR>memory used: " + toMB(pool.getMemoryUsed()));
out.write("<BR>total capacity: " + toMB(pool.getTotalCapacity()));
out.write("<BR><BR><BR><BR>");
}
%>
<%!
private static String toMB(long init) {
return (Long.valueOf(init).doubleValue() / (1024 * 1024)) + " MB";
}
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment