void () { try { for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) { if (bean.getType() == MemoryType.HEAP && bean.isCollectionUsageThresholdSupported() && bean.isUsageThresholdSupported()) { long max = bean.getUsage().getMax(); long threshold = Math.min((long)(max * getOccupiedMemoryThreshold()), max - MEM_THRESHOLD); if (threshold > 0) { bean.setUsageThreshold(threshold); bean.setCollectionUsageThreshold(threshold); } } } ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(myLowMemoryListener, null, null); } catch (Throwable e) { // should not happen normally getLogger().info("Errors initializing LowMemoryWatcher: ", e); } }