Source:
synchronized void fetchAndUpdateCache() { try { if (mySqlAccountStore == null) { try { mySqlAccountStore = mySqlAccountStoreFactory.getMySqlAccountStore(true); } catch (SQLException e) { logger.error("MySQL account store creation failed", e); } } long lastModifiedTime = accountInfoMapRef.get().getLastModifiedTime(); Collection<Account> updatedAccountsInDB = mySqlAccountStore.getNewAccounts(lastModifiedTime); Collection<Container> updatedContainersInDB = mySqlAccountStore.getNewContainers(lastModifiedTime); if (!updatedAccountsInDB.isEmpty() || !updatedContainersInDB.isEmpty()) { infoMapLock.writeLock().lock(); try { AccountInfoMap accountInfoMap = accountInfoMapRef.get(); accountInfoMap.addOrUpdateAccounts(updatedAccountsInDB); accountInfoMap.addOrUpdateContainers(updatedContainersInDB); accountInfoMap.refreshLastModifiedTime(); } finally { infoMapLock.writeLock().unlock(); } needRefresh = false; Collection<Account> updatedAccounts = updatedContainersInDB.stream() .map(container -> accountInfoMapRef.get().getAccountById(container.getParentAccountId())) .collect(Collectors.toSet()); notifyAccountUpdateConsumers(updatedAccounts, false); Collection<Account> accountCollection; infoMapLock.readLock().lock(); try { accountCollection = accountInfoMapRef.get().getAccounts(); } finally { infoMapLock.readLock().unlock(); } Map<String, String> accountMap = new HashMap<>(); accountCollection.forEach( account -> accountMap.put(Short.toString(account.getId()), account.toJson(false).toString())); backupFileManager.persistAccountMap(accountMap, backupFileManager.getLatestVersion() + 1, SystemTime.getInstance().seconds()); } } catch (SQLException e) { logger.error("Fetching Accounts from MySql DB failed", e); } }

Target:
synchronized void fetchAndUpdateCache() { try { if (mySqlAccountStore == null) { try { mySqlAccountStore = mySqlAccountStoreFactory.getMySqlAccountStore(true); } catch (SQLException e) { logger.error("MySQL account store creation failed", e); } } long lastModifiedTime = accountInfoMapRef.get().getLastModifiedTime(); Collection<Account> updatedAccountsInDB = mySqlAccountStore.getNewAccounts(lastModifiedTime); Collection<Container> updatedContainersInDB = mySqlAccountStore.getNewContainers(lastModifiedTime); if (!updatedAccountsInDB.isEmpty() || !updatedContainersInDB.isEmpty()) { infoMapLock.writeLock().lock(); try { AccountInfoMap accountInfoMap = accountInfoMapRef.get(); accountInfoMap.addOrUpdateAccounts(updatedAccountsInDB); accountInfoMap.addOrUpdateContainers(updatedContainersInDB); accountInfoMap.refreshLastModifiedTime(); } finally { infoMapLock.writeLock().unlock(); } needRefresh = false; Set<Account> updatedAccounts = new HashSet<>(); updatedAccountsInDB.forEach( account -> updatedAccounts.add(accountInfoMapRef.get().getAccountById(account.getId()))); updatedContainersInDB.forEach( container -> updatedAccounts.add(accountInfoMapRef.get().getAccountById(container.getParentAccountId()))); notifyAccountUpdateConsumers(updatedAccounts, false); Collection<Account> accountCollection; infoMapLock.readLock().lock(); try { accountCollection = accountInfoMapRef.get().getAccounts(); } finally { infoMapLock.readLock().unlock(); } Map<String, String> accountMap = new HashMap<>(); accountCollection.forEach( account -> accountMap.put(Short.toString(account.getId()), account.toJson(false).toString())); backupFileManager.persistAccountMap(accountMap, backupFileManager.getLatestVersion() + 1, SystemTime.getInstance().seconds()); } } catch (SQLException e) { logger.error("Fetching Accounts from MySql DB failed", e); } }