32 lines
726 B
Java
32 lines
726 B
Java
|
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.intValue());
|
||
|
System.out.printf("Unsafe allocation: %d%n", unsafeAllocation.intValue());
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
private Profiler() {
|
||
|
}
|
||
|
|
||
|
|
||
|
public static void addSafeAllocation(){
|
||
|
safeAllocations.increment();
|
||
|
}
|
||
|
|
||
|
public static void addUnsafeAllocation(){
|
||
|
unsafeAllocation.increment();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|