Java 8 GarbageCollectorMXBean - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 GarbageCollectorMXBean class.

This code example shows how to use the following methods:getCollectionCount, getCollectionTime, getName
    private final GarbageCollectorMXBean gc = mock(GarbageCollectorMXBean.class);
    private final GarbageCollectorMetricSet metrics = new GarbageCollectorMetricSet(Arrays.asList(gc));
 
    @Before 
    public void setUp() throws Exception {
        when(gc.getName()).thenReturn("PS OldGen");
        when(gc.getCollectionCount()).thenReturn(1L);
        when(gc.getCollectionTime()).thenReturn(2L);
    } 
 
    @Test
    public void hasGaugesForGcCountsAndElapsedTimes() throws Exception {
        assertThat(metrics.getMetrics().keySet())
                .containsOnly("PS-OldGen.time", "PS-OldGen.count"); 
    } 
 
    @Test
    public void hasAGaugeForGcCounts() throws Exception {
        final Gauge gauge = (Gauge) metrics.getMetrics().get("PS-OldGen.count");
        assertThat(gauge.getValue())
4
CodeRank
This code example shows how to use the following methods:getCollectionCount
            return lastCollectionTime - prev;
        } 
 
        public long updateCollectionCount() { 
            long prev = lastCollectionCount;
            lastCollectionCount = mxBean.getCollectionCount();
            return lastCollectionCount - prev;
        } 
    } 
 
    private final int interval;
    private final int logThreshold;
    private final List<GCInfo> gcInfo = new ArrayList<>();
    private final MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    private volatile boolean running;
 
 
    public GCMonitor(int interval, int logThreshold) {
        super(THREAD_NAME);
        this.interval = interval;
4
CodeRank
See Code Examples for Java 8 GarbageCollectorMXBean Methods: