diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java index 785202b..304a85b 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java @@ -119,13 +119,12 @@ public abstract class AccountingPersistenceBackendFactory { logger.debug("The {} for scope {} is {}. Is time to rediscover if there is another possibility.", AccountingPersistenceBackend.class.getSimpleName(), scope, actual.getClass().getSimpleName()); - lock.lock(); try { - logger.trace("Renewing Last check Timestamp. The next one will be {}", now); - fallbackLastCheck.put(scope, now); - lastCheckTimestamp = fallbackLastCheck.get(scope); + AccountingPersistenceBackend discoveredPersistenceBackend = discoverAccountingPersistenceBackend(scope); + + lock.lock(); if(discoveredPersistenceBackend!=null){ // Passing the aggregator to the new AccountingPersistenceBackend // so that the buffered records will be persisted with the new method @@ -143,6 +142,10 @@ public abstract class AccountingPersistenceBackendFactory { } lock.unlock(); return discoveredPersistenceBackend; + }else{ + logger.trace("Renewing Last check Timestamp. The next one will be {}", now); + fallbackLastCheck.put(scope, now); + lastCheckTimestamp = fallbackLastCheck.get(scope); } }finally { lock.unlock(); @@ -159,7 +162,7 @@ public abstract class AccountingPersistenceBackendFactory { return actual; } - protected static synchronized AccountingPersistenceBackend getPersistenceBackend() { + protected static AccountingPersistenceBackend getPersistenceBackend() { String scope = ScopeProvider.instance.get(); if(scope==null){