Search in sources :

Example 16 with NotificationEmitter

use of javax.management.NotificationEmitter in project Lucee by lucee.

the class MemoryControler method init.

public static synchronized void init(ConfigServer cs) {
    if (init)
        return;
    // set level
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        types.put(pool.getName(), pool.getType());
        // we should rather check for the pool name "Tenured Gen"?
        if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
            long maxMemory = pool.getUsage().getMax();
            long warningThreshold = (long) (maxMemory * 0.9);
            // long warningThreshold = maxMemory -(10*1024*1024);
            pool.setUsageThreshold(warningThreshold);
        }
    }
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    MemoryNotificationListener listener = new MemoryNotificationListener(types);
    emitter.addNotificationListener(listener, null, cs);
    init = true;
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) NotificationEmitter(javax.management.NotificationEmitter) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Aggregations

NotificationEmitter (javax.management.NotificationEmitter)16 NotificationListener (javax.management.NotificationListener)7 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)5 ListenerNotFoundException (javax.management.ListenerNotFoundException)5 MemoryMXBean (java.lang.management.MemoryMXBean)3 Notification (javax.management.Notification)3 ObjectName (javax.management.ObjectName)3 ScanState (com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState)2 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 AttributeChangeNotification (javax.management.AttributeChangeNotification)2 MBeanServer (javax.management.MBeanServer)2 NotificationFilter (javax.management.NotificationFilter)2 CounterMonitor (javax.management.monitor.CounterMonitor)2 CounterMonitorMBean (javax.management.monitor.CounterMonitorMBean)2 Duration (com.github.joschi.jadconfig.util.Duration)1 GcInfo (com.sun.management.GcInfo)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Proxy (java.lang.reflect.Proxy)1