AJP/DiSLProject2022/src-profiler/ex5/Profiler.java
2023-01-09 08:01:15 +01:00

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();
}
}