From 135542b53f12c4e2094e4bf18179a8f932603317 Mon Sep 17 00:00:00 2001 From: DenChaykovskiy Date: Fri, 17 May 2024 11:49:02 +0200 Subject: [PATCH] storage-mgr: synchro create file will be unlocked after exceptions --- .../dlr/proseo/storagemgr/utils/FileUtils.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/storage-mgr/src/main/java/de/dlr/proseo/storagemgr/utils/FileUtils.java b/storage-mgr/src/main/java/de/dlr/proseo/storagemgr/utils/FileUtils.java index b6e363d44..09984f43d 100644 --- a/storage-mgr/src/main/java/de/dlr/proseo/storagemgr/utils/FileUtils.java +++ b/storage-mgr/src/main/java/de/dlr/proseo/storagemgr/utils/FileUtils.java @@ -95,8 +95,12 @@ public boolean createFile(String content) { } /** - * Creates the file with the content in a synchronized modus. Returns false if the file was not created/rewritten. - * creation of the file was not successfully + * Creates the file with the content in a synchronized modus. Returns false if + * the file was not created/rewritten. creation of the file was not + * successfully. The waiting thread will unlock the file, which was locked in + * the locked thread in case of exception - Timeout or Interrupted exception. It + * is made for unlocking auxiliary files (status and accessed) of the storage + * manager. Please use this synchronized function carefully. * * @param content Content of the file * @param waitTime the wait time between each cycle of checking the @@ -119,18 +123,21 @@ public boolean synchroCreateFile(String content, long waitTime, long fileCheckMa fileLocker.lockOrWaitUntilUnlockedAndLock(); fileCreatedStatus = createFile(content); - fileLocker.unlock(); fileCreatedStatus = true; } catch (FileLockedAfterMaxCyclesException e) { - logger.debug("... the synchronized file was not created/rewritten: waiting timeout (possible locked from another thread): " - + path + " " + e.getMessage()); + logger.debug( + "... the synchronized file was not created/rewritten: waiting timeout (possible locked from another thread): " + + path + " " + e.getMessage()); } catch (InterruptedException e) { logger.debug("... the syncronized file was not created/rewritten: interrupted exception: " + path + " " + e.getMessage()); + } finally { + + fileLocker.unlock(); } return fileCreatedStatus;