public final class MemoryWarningSystem { private static MemoryWarningSystem m_instance = null; /** * Listener to be notified on warning events */ public interface MemoryWarningListener { /** * @param usedMemory * @param maxMemory */ public void memoryUsageLow(long usedMemory, long maxMemory); } private final Set<MemoryWarningListener> listeners = new HashSet<MemoryWarningListener>(); private final MemoryPoolMXBean m_memPool = findTenuredGenPool(); /** * Singleton here? */ private MemoryWarningSystem() { final long maxMem = computeMaxMem(); MemoryMXBean mbean = ManagementFactory.getMemoryMXBean(); NotificationEmitter emitter = (NotificationEmitter)mbean; emitter.addNotificationListener(new NotificationListener() { @Override
使用JMX实现的内存监控
最新推荐文章于 2024-04-18 07:30:00 发布