3 ms·
You are correct. The solution is to use a static constructor method, like this: public static Profiler newInstance(Options options) { Profiler prof
by layer8 4y ago
You are correct. The solution is to use a static constructor method, like this:
public static Profiler newInstance(Options options) {
Profiler profiler = new Profiler(options);
Runtime.getRuntime().addShutdownHook(new Thread(profiler::onEnd));
return profiler;
}
private Profiler(Options options) {
this.options = options;
this.store = new Store(options.getFlamePath());
}
In principle you can also use chained constructors:
public Profiler(Options options) {
this(options, null);
Runtime.getRuntime().addShutdownHook(new Thread(this::onEnd)); // okay to leak this here
}
private Profiler(Options options, Void dummy) {
this.options = options;
this.store = new Store(options.getFlamePath());
}
(cf. https://stackoverflow.com/a/35169705/623763 https://stackoverflow.com/a/35169705/623763)
- parttimenerd 4y agoThank you. I fixed the code in the GitHub repository but kept the code on my blog the same, with a disclaimer regarding its problems.