LowMemoryDetector.java 文件源码

java
阅读 14 收藏 0 点赞 0 评论 0

项目:scaleDOM 作者:
/**
 * Default constructor.
 * 
 * @param memoryThresholdFactor amount of memory to be considered 'enough memory'.
 * @throws IllegalArgumentException If memoryThresholdFactor is not strictly between 0.0 and 1.0.
 */
public LowMemoryDetector(final double memoryThresholdFactor) {
    checkArgument(memoryThresholdFactor > 0.0 && memoryThresholdFactor < 1.0,
            "Expected memoryThresholdFactor to be between 0.0 and 1.0, %s is not.", memoryThresholdFactor);

    isLowMemory = false;

    // Find the tenured heap
    tenuredHeap = findTenuredHeap();
    checkNotNull(tenuredHeap, "Expected tenuredHeap to be not null.");
    tenuredHeapSize = tenuredHeap.getUsage().getMax();
    log.debug("Determined the tenured heap as '{}' (size: {} B).", tenuredHeap.getName(), tenuredHeapSize);

    // Monitor tenured heap
    memoryThreshold = (long) (tenuredHeapSize * memoryThresholdFactor);
    tenuredHeap.setCollectionUsageThreshold(memoryThreshold);
    log.debug("Low memory threshold is {} B.", memoryThreshold);

    // Add notification listener
    final NotificationEmitter notificationEmitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    notificationEmitter.addNotificationListener(this, null, null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号