Skip to content

Commit

Permalink
Remove unnecessary use of ConcurrentHashMap in GcLogger
Browse files Browse the repository at this point in the history
GcLogger was using a ConcurrentHashMap that was only written to in its constructor;
switch to an unmodifiable HashMap.
  • Loading branch information
kilink committed Oct 31, 2023
1 parent d5b30df commit 7b11fd1
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
Expand Down Expand Up @@ -88,7 +89,7 @@ public final class GcLogger {

private final long jvmStartTime;

private final ConcurrentHashMap<String, CircularBuffer<GcEvent>> gcLogs = new ConcurrentHashMap<>();
private final Map<String, CircularBuffer<GcEvent>> gcLogs;

private long youngGenSizeAfter = 0L;

Expand All @@ -105,10 +106,12 @@ public final class GcLogger {
/** Create a new instance. */
public GcLogger() {
jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
Map<String, CircularBuffer<GcEvent>> gcLogs = new HashMap<>();
for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) {
CircularBuffer<GcEvent> buffer = new CircularBuffer<>(BUFFER_SIZE);
gcLogs.put(mbean.getName(), buffer);
}
this.gcLogs = Collections.unmodifiableMap(gcLogs);

for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
String poolName = mbean.getName();
Expand Down

0 comments on commit 7b11fd1

Please sign in to comment.