diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java index 0563f62..699a21e 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendMonitor.java @@ -79,12 +79,14 @@ public class AccountingPersistenceBackendMonitor implements Runnable { } if(elaborationFile!=null){ - elaborateFile(elaborationFile); - boolean deleted = elaborationFile.delete(); - if(!deleted){ - logger.debug("Failed to delete file {}", elaborationFile.getAbsolutePath()); - File elaborationFileNotDeleted = new File(elaborationFile.getAbsolutePath()+ELABORATION_FILE_NOT_DELETED_SUFFIX); - elaborationFile.renameTo(elaborationFileNotDeleted); + synchronized (elaborationFile) { + elaborateFile(elaborationFile); + boolean deleted = elaborationFile.delete(); + if(!deleted){ + logger.debug("Failed to delete file {}", elaborationFile.getAbsolutePath()); + File elaborationFileNotDeleted = new File(elaborationFile.getAbsolutePath()+ELABORATION_FILE_NOT_DELETED_SUFFIX); + elaborationFile.renameTo(elaborationFileNotDeleted); + } } }