package ex5; import java.util.concurrent.atomic.LongAdder; public final class Profiler { private static final LongAdder safeAllocations = new LongAdder(); private static final LongAdder unsafeAllocation = new LongAdder(); static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { System.out.printf("Safe allocation: %d%n", safeAllocations.longValue()); System.out.printf("Unsafe allocation: %d%n", unsafeAllocation.longValue()); })); } private Profiler() { } public static void addSafeAllocation(){ safeAllocations.increment(); } public static void addUnsafeAllocation(){ unsafeAllocation.increment(); } }