像这样的类应该在哪里添加 try-with-resources 以便正确关闭资源?我认为应该如图所示重用附加程序,对吗?
public class ChronicleWriter implements UpdateListener {
private ExcerptAppender appender;
private SingleChronicleQueue queue;
public ChronicleWriter(Path p) {
queue = SingleChronicleQueueBuilder.binary(p).build();
appender = queue.acquireAppender();
}
@Override
public void onUpdate(String text) {
appender.writeText(text);
}
}