我正在使用 CronicleQueue,但我只有一位作家/读者。想要在阅读器完成 CQ4 文件后立即进行清理。以下代码无法删除文件,在 onReleased() 事件期间 CQ 是否仍持有文件引用?
public class ChronicleFactory {
public SingleChronicleQueue createChronicle(String instance, String persistenceDir, RollCycles rollCycles) {
SingleChronicleQueue chronicle = null;
String thisInstance = instance;
try {
chronicle = SingleChronicleQueueBuilder.binary(persistenceDir).rollCycle(rollCycles).storeFileListener(new StoreFileListener() {
@Override
public void onReleased(int i, File file) {
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy??-MM-dd HH:mm:ss.SSS"));
System.out.println(instance + "> " + currentTime + ": " + Thread.currentThread().getName() + " onReleased called for file: " + file.getAbsolutePath() + " for cycle: " + i);
if(instance.equals("Reader")) {
System.out.println("Removing previous CQ file: " + file.getName() + ", deleted? " + file.delete()); //==> Not able to delete the file !!!
}
}
.....