This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
AJP/DiSLProject2022/src-profiler/ex5/Profiler.java

32 lines
726 B
Java
Raw Normal View History

2023-01-09 07:01:15 +00:00
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();
}
}