gpt4 book ai didi

java - CollectionUsage、PeakUsage、Usage 之间有什么区别?

转载 作者:行者123 更新时间:2023-11-29 06:21:11 24 4
gpt4 key购买 nike

任何内存池 bean 中的 CollectionUsage、PeakUsage、Usage 字段有什么区别?
我在 jconsole 窗口中的任何应用程序的路径中看到了这些:
mbeans 选项卡 > java.lang > memorypool > 选择任何 bean。
右侧 Pane 中,我们可以看到这些属性。

最佳答案

它们都在 MemoryPoolMXBean 的 javadocs 中描述。

Memory Usage

The getUsage() method provides an estimate of the current usage of a memory pool. For a garbage-collected memory pool, the amount of used memory includes the memory occupied by all objects in the pool including both reachable and unreachable objects.

In general, this method is a lightweight operation for getting an approximate memory usage. For some memory pools, for example, when objects are not packed contiguously, this method may be an expensive operation that requires some computation to determine the current memory usage. An implementation should document when this is the case.

Peak Memory Usage

The Java virtual machine maintains the peak memory usage of a memory pool since the virtual machine was started or the peak was reset. The peak memory usage is returned by the getPeakUsage() method and reset by calling the resetPeakUsage() method.

Collection Usage Threshold

Collection usage threshold is a manageable attribute only applicable to some garbage-collected memory pools. After a Java virtual machine has expended effort in reclaiming memory space by recycling unused objects in a memory pool at garbage collection time, some number of bytes in the memory pools that are garbaged collected will still be in use. The collection usage threshold allows a value to be set for this number of bytes such that if the threshold is exceeded, a collection usage threshold exceeded notification will be emitted by the MemoryMXBean. In addition, the collection usage threshold count will then be incremented.

The isCollectionUsageThresholdSupported() method can be used to determine if this functionality is supported.

A Java virtual machine performs collection usage threshold checking on a memory pool basis. This checking is enabled if the collection usage threshold is set to a positive value. If the collection usage threshold is set to zero, this checking is disabled on this memory pool. Default value is zero. The Java virtual machine performs the collection usage threshold checking at garbage collection time.

Some garbage-collected memory pools may choose not to support the collection usage threshold. For example, a memory pool is only managed by a continuous concurrent garbage collector. Objects can be allocated in this memory pool by some thread while the unused objects are reclaimed by the concurrent garbage collector simultaneously. Unless there is a well-defined garbage collection time which is the best appropriate time to check the memory usage, the collection usage threshold should not be supported.

The collection usage threshold is designed for monitoring the memory usage after the Java virtual machine has expended effort in reclaiming memory space. The collection usage could also be monitored by the polling and threshold notification mechanism described above for the usage threshold in a similar fashion.

关于java - CollectionUsage、PeakUsage、Usage 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2974915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com