I am have a resource I open on construction of my object. I use it to write throughout the lifetime of the object. But my application can close without warning and I need to capture this. The class is pretty straightforward.
public class SomeWriter {
private Metrics metrics;
public SomeWriter() {
try (metrics = new Metrics()) { // I know I can't but the idea is there
}
}
public void write(String blah) {
metrics.write(blah);
}
public void close() {
metrics.close();
}
So, you get the idea. I'd like to "Autoclose" Metrics if the application goes down.