Ripristinati lock e unlock

This commit is contained in:
2025-04-24 11:02:53 +02:00
parent 794612fc16
commit 4e97fa1d56
5 changed files with 173 additions and 161 deletions

View File

@@ -12,7 +12,7 @@ import java.util.concurrent.locks.ReentrantLock;
@Service @Service
public class EmsDBConst { public class EmsDBConst {
// private final ReentrantLock datiAziendaLock = new ReentrantLock(); private final ReentrantLock datiAziendaLock = new ReentrantLock();
private HashMap<String, Const> datiAziendaBindingTable = new HashMap<String, Const>() {{ private HashMap<String, Const> datiAziendaBindingTable = new HashMap<String, Const>() {{
}}; }};
@@ -28,24 +28,24 @@ public class EmsDBConst {
public Const getConsts(String dbName) { public Const getConsts(String dbName) {
String aziendaUp = dbName.toUpperCase(); String aziendaUp = dbName.toUpperCase();
// datiAziendaLock.lock(); datiAziendaLock.lock();
if (!datiAziendaBindingTable.containsKey(aziendaUp)) { try {
datiAziendaBindingTable.put(aziendaUp, new Const()); if (!datiAziendaBindingTable.containsKey(aziendaUp)) {
datiAziendaBindingTable.put(aziendaUp, new Const());
}
return datiAziendaBindingTable.get(aziendaUp);
} finally {
datiAziendaLock.unlock();
} }
final Const aConst = datiAziendaBindingTable.get(aziendaUp);
// datiAziendaLock.unlock();
return aConst;
} }
public void destroyAll() { public void destroyAll() {
// datiAziendaLock.lock(); datiAziendaLock.lock();
datiAziendaBindingTable = new HashMap<>(); datiAziendaBindingTable = new HashMap<>();
// datiAziendaLock.unlock(); datiAziendaLock.unlock();
} }
public static class Const { public static class Const {
private String applicationDbName; private String applicationDbName;

View File

@@ -19,6 +19,7 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@@ -32,7 +33,7 @@ public class UnitaTerritorialiService {
// Data di ultima modifica // Data di ultima modifica
private Instant lastModifiedSource = Instant.MIN; private Instant lastModifiedSource = Instant.MIN;
// Locker per la sincronizzazione // Locker per la sincronizzazione
// private final ReentrantLock updateLocker = new ReentrantLock(); private final ReentrantLock updateLocker = new ReentrantLock();
// Dati transcodificati // Dati transcodificati
private List<IstatComuneDataRow> dataSource = new ArrayList<>(); private List<IstatComuneDataRow> dataSource = new ArrayList<>();
private List<Regione> regioni = new ArrayList<>(); private List<Regione> regioni = new ArrayList<>();
@@ -77,13 +78,13 @@ public class UnitaTerritorialiService {
return; return;
} }
// updateLocker.lock(); updateLocker.lock();
try (InputStream streamIstat = connectionIstat.getInputStream()) { try (InputStream streamIstat = connectionIstat.getInputStream()) {
if (updateServiceData(streamIstat)) { if (updateServiceData(streamIstat)) {
lastModifiedSource = Instant.now(); // Recupera la data di modifica dal server lastModifiedSource = Instant.now(); // Recupera la data di modifica dal server
} }
} finally { } finally {
// updateLocker.unlock(); updateLocker.unlock();
} }
} }

View File

@@ -15,6 +15,7 @@ import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
@Component @Component
public class BasicConnectionPool { public class BasicConnectionPool {
@@ -29,21 +30,21 @@ public class BasicConnectionPool {
private final ConcurrentHashMap<String, AtomicInteger> extraConnectionCounters = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, AtomicInteger> extraConnectionCounters = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, Set<String>> activeConnectionNames = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, Set<String>> activeConnectionNames = new ConcurrentHashMap<>();
// private final ReentrantLock poolLock = new ReentrantLock(); private final ReentrantLock poolLock = new ReentrantLock();
public void init() throws Exception { public void init() throws Exception {
// poolLock.lock(); poolLock.lock();
try { try {
closeAllConnections(); closeAllConnections();
int poolSize = calculatePoolSize(); int poolSize = calculatePoolSize();
initializeConnections(poolSize); initializeConnections(poolSize);
} finally { } finally {
// poolLock.unlock(); poolLock.unlock();
} }
} }
private void closeAllConnections() { private void closeAllConnections() {
// poolLock.lock(); poolLock.lock();
try { try {
// Chiude tutte le connessioni esistenti // Chiude tutte le connessioni esistenti
connectionPool.values().forEach(connections -> connectionPool.values().forEach(connections ->
@@ -57,7 +58,7 @@ public class BasicConnectionPool {
extraConnectionCounters.clear(); extraConnectionCounters.clear();
activeConnectionNames.clear(); activeConnectionNames.clear();
} finally { } finally {
// poolLock.unlock(); poolLock.unlock();
} }
} }
@@ -127,21 +128,16 @@ public class BasicConnectionPool {
return null; return null;
} }
// poolLock.lock(); poolLock.lock();
try { try {
if (!connectionPool.containsKey(dbName)|| connectionPool.get(dbName).isEmpty()) { if (!connectionPool.containsKey(dbName) || connectionPool.get(dbName).isEmpty()) {
return createExtraConnection(profileName); return createExtraConnection(profileName);
} }
List<DataSource> pool = connectionPool.get(dbName); List<DataSource> pool = connectionPool.get(dbName);
List<DataSource> used = usedConnections.get(dbName); List<DataSource> used = usedConnections.get(dbName);
DataSource ds; DataSource ds = pool.remove(0);
try {
ds = pool.remove(0);
} catch (IndexOutOfBoundsException ex) {
return createExtraConnection(profileName);
}
if (ds.isClosed()) { if (ds.isClosed()) {
String oldName = ds.getApplicationName(); String oldName = ds.getApplicationName();
@@ -157,7 +153,7 @@ public class BasicConnectionPool {
logger.trace("Assigned connection: {} for database: {}", ds.getApplicationName(), dbName); logger.trace("Assigned connection: {} for database: {}", ds.getApplicationName(), dbName);
return ds; return ds;
} finally { } finally {
// poolLock.unlock(); poolLock.unlock();
} }
} }
@@ -167,7 +163,7 @@ public class BasicConnectionPool {
return false; return false;
} }
// poolLock.lock(); poolLock.lock();
try { try {
String currentCatalog = ds.getConnection().getCatalog(); String currentCatalog = ds.getConnection().getCatalog();
AvailableConnectionsModel model = findConnectionModel(profileName); AvailableConnectionsModel model = findConnectionModel(profileName);
@@ -183,13 +179,13 @@ public class BasicConnectionPool {
return handleConnectionRelease(ds); return handleConnectionRelease(ds);
} finally { } finally {
// poolLock.unlock(); poolLock.unlock();
} }
} }
private DataSource createExtraConnection(String profileName) throws Exception { private DataSource createExtraConnection(String profileName) throws Exception {
String dbName = settingsModel.getDbNameFromProfileDb(profileName); String dbName = settingsModel.getDbNameFromProfileDb(profileName);
// poolLock.lock(); poolLock.lock();
try { try {
// Calcola il numero totale di connessioni esistenti // Calcola il numero totale di connessioni esistenti
int baseCount = connectionPool.get(dbName).size() + usedConnections.get(dbName).size(); int baseCount = connectionPool.get(dbName).size() + usedConnections.get(dbName).size();
@@ -201,7 +197,6 @@ public class BasicConnectionPool {
// Verifica se la connessione esiste già // Verifica se la connessione esiste già
if (activeConnectionNames.get(dbName).contains(connectionName)) { if (activeConnectionNames.get(dbName).contains(connectionName)) {
logger.warn("Extra connection name collision detected: {}", connectionName); logger.warn("Extra connection name collision detected: {}", connectionName);
// extraConnectionCounters.get(dbName).decrementAndGet();
return createExtraConnection(profileName); // Riprova con un nuovo nome return createExtraConnection(profileName); // Riprova con un nuovo nome
} }
@@ -212,7 +207,7 @@ public class BasicConnectionPool {
logger.trace("Created extra connection: {} for database: {}", connectionName, dbName); logger.trace("Created extra connection: {} for database: {}", connectionName, dbName);
return ds; return ds;
} finally { } finally {
// poolLock.unlock(); poolLock.unlock();
} }
} }

View File

@@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@@ -35,7 +36,7 @@ public class MultiDBTransactionManager implements AutoCloseable {
private List<AdvancedDataSource> dbDatasources = new ArrayList<>(); private List<AdvancedDataSource> dbDatasources = new ArrayList<>();
private DataSource dataSource; private DataSource dataSource;
// private final ReentrantLock datasourcesLock = new ReentrantLock(); private final ReentrantLock datasourcesLock = new ReentrantLock();
@Autowired @Autowired
private BasicConnectionPool connectionPool; private BasicConnectionPool connectionPool;
@@ -89,7 +90,6 @@ public class MultiDBTransactionManager implements AutoCloseable {
this.setPrimaryDs(profileDb); this.setPrimaryDs(profileDb);
} catch (Exception ex) { } catch (Exception ex) {
logger.error("Errore durante la connessione al DB.", ex); logger.error("Errore durante la connessione al DB.", ex);
// throw ex;
} }
} }
@@ -135,20 +135,22 @@ public class MultiDBTransactionManager implements AutoCloseable {
} }
} }
// datasourcesLock.lock(); datasourcesLock.lock();
dbDatasources.add(new AdvancedDataSource(profileName, dataSource, isDistributore, isInternalDb)); try {
dbDatasources.add(new AdvancedDataSource(profileName, dataSource, isDistributore, isInternalDb));
if (isDistributore) { if (isDistributore) {
dbDatasources = dbDatasources.stream() dbDatasources = dbDatasources.stream()
.sorted((o1, o2) -> { .sorted((o1, o2) -> {
if (o1.getIsDistributore() && !o2.getIsDistributore()) return -1; if (o1.getIsDistributore() && !o2.getIsDistributore()) return -1;
else if (!o1.getIsDistributore() && o2.getIsDistributore()) return 1; else if (!o1.getIsDistributore() && o2.getIsDistributore()) return 1;
else return 0; else return 0;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
}
} finally {
datasourcesLock.unlock();
} }
// datasourcesLock.unlock();
} }
} }
@@ -243,34 +245,36 @@ public class MultiDBTransactionManager implements AutoCloseable {
} }
public void closeAll() throws Exception { public void closeAll() throws Exception {
// datasourcesLock.lock(); datasourcesLock.lock();
if (dbDatasources != null && !dbDatasources.isEmpty()) { try {
for (AdvancedDataSource advancedDataSource : dbDatasources) { if (dbDatasources != null && !dbDatasources.isEmpty()) {
for (AdvancedDataSource advancedDataSource : dbDatasources) {
if (requestData != null && requestData.getRequestURI() != null) { if (requestData != null && requestData.getRequestURI() != null) {
String methodName = " [" + requestData.getRequestURI() + "]"; String methodName = " [" + requestData.getRequestURI() + "]";
if (shouldPrintLog(requestData.getRequestURI())) if (shouldPrintLog(requestData.getRequestURI()))
logger.debug("Closing automatically: " + advancedDataSource.getDataSource().getProfile() + " (#" + advancedDataSource.getDataSource().getSessionID() + ")" + methodName); logger.debug("Closing automatically: " + advancedDataSource.getDataSource().getProfile() + " (#" + advancedDataSource.getDataSource().getSessionID() + ")" + methodName);
} else if (enableLog) { } else if (enableLog) {
logger.debug("Closing manually: " + advancedDataSource.getDataSource().getProfile() + " (#" + advancedDataSource.getDataSource().getSessionID() + ")"); logger.debug("Closing manually: " + advancedDataSource.getDataSource().getProfile() + " (#" + advancedDataSource.getDataSource().getSessionID() + ")");
} }
advancedDataSource.commit(); advancedDataSource.commit();
try {
connectionPool.releaseConnection(advancedDataSource.getProfileName(), advancedDataSource.getDataSource());
} catch (UnexpectedConnectionSwitchException e) {
logger.error("UnexpectedConnectionSwitchException: " + advancedDataSource.getProfileName(), e);
}
if (dbPrimary != null && advancedDataSource.getDataSource() == dbPrimary.getDataSource())
dbPrimary = null;
try {
connectionPool.releaseConnection(advancedDataSource.getProfileName(), advancedDataSource.getDataSource());
} catch (UnexpectedConnectionSwitchException e) {
logger.error("UnexpectedConnectionSwitchException: " + advancedDataSource.getProfileName(), e);
} }
if(dbPrimary != null && advancedDataSource.getDataSource() == dbPrimary.getDataSource()) dbDatasources.clear();
dbPrimary = null;
} }
} finally {
dbDatasources.clear(); datasourcesLock.unlock();
} }
// datasourcesLock.unlock();
} }

View File

@@ -38,13 +38,13 @@ public class UserCacheService {
private final HashMap<String, List<UserDTO>> cachedUsers = new HashMap<>(); private final HashMap<String, List<UserDTO>> cachedUsers = new HashMap<>();
//private final ReentrantLock cacheLock = new ReentrantLock(); private final ReentrantLock cacheLock = new ReentrantLock();
boolean canStart = false; boolean canStart = false;
@PostContextConstruct(priority = 10) @PostContextConstruct(priority = 10)
private void init() { private void init() {
if(UtilityDebug.isDebugExecution()) internalCacheUpdate(true); if (UtilityDebug.isDebugExecution()) internalCacheUpdate(true);
canStart = !UtilityDebug.isDebugExecution(); canStart = !UtilityDebug.isDebugExecution();
} }
@@ -54,7 +54,7 @@ public class UserCacheService {
} }
private void internalCacheUpdate(boolean forceStart) { private void internalCacheUpdate(boolean forceStart) {
if(!forceStart && !canStart) return; if (!forceStart && !canStart) return;
List<AvailableConnectionsModel> availableConnectionsModels = List<AvailableConnectionsModel> availableConnectionsModels =
settingsModel.getAvailableConnectionsWithoutDuplicatedProfiles(true); settingsModel.getAvailableConnectionsWithoutDuplicatedProfiles(true);
@@ -103,127 +103,139 @@ public class UserCacheService {
} }
public @Nullable UserDTO retrieveUser(String dbName, String md5User) { public @Nullable UserDTO retrieveUser(String dbName, String md5User) {
//cacheLock.lock(); cacheLock.lock();
List<UserDTO> users = cachedUsers.getOrDefault(dbName, null); try {
List<UserDTO> users = cachedUsers.getOrDefault(dbName, null);
if (users == null || users.isEmpty()) if (users == null || users.isEmpty())
return null; return null;
if (md5User == null || md5User.isEmpty()) if (md5User == null || md5User.isEmpty())
return null; return null;
final Optional<UserDTO> foundUser = users.stream() final Optional<UserDTO> foundUser = users.stream()
.filter(x -> { .filter(x -> {
String md5Hash = UtilityHash.generateMd5(String.format("%s%s", x.getUsername().toLowerCase(), x.getPassword().toLowerCase())); String md5Hash = UtilityHash.generateMd5(String.format("%s%s", x.getUsername().toLowerCase(), x.getPassword().toLowerCase()));
return md5Hash.contentEquals(md5User); return md5Hash.contentEquals(md5User);
}) })
.findFirst(); .findFirst();
//cacheLock.unlock(); return foundUser.orElse(null);
return foundUser.orElse(null); } finally {
cacheLock.unlock();
}
} }
public @Nullable UserDTO retrieveUser(String dbName, String username, String password, IntegryApplicationEnum application) { public @Nullable UserDTO retrieveUser(String dbName, String username, String password, IntegryApplicationEnum application) {
//cacheLock.lock(); cacheLock.lock();
List<UserDTO> users = cachedUsers.getOrDefault(dbName, null); try {
List<UserDTO> users = cachedUsers.getOrDefault(dbName, null);
if (users == null || users.isEmpty()) if (users == null || users.isEmpty())
return null; return null;
if (password == null || password.isEmpty()) if (password == null || password.isEmpty())
return null; return null;
String finalPasswordHex = UtilityHash.generateHash(password.toUpperCase()); String finalPasswordHex = UtilityHash.generateHash(password.toUpperCase());
final Optional<UserDTO> foundUser = users.stream() final Optional<UserDTO> foundUser = users.stream()
.filter(x -> x.getUsername().equalsIgnoreCase(username) && .filter(x -> x.getUsername().equalsIgnoreCase(username) &&
x.isAttivo() && x.isAttivo() &&
x.getPasswordHash().contentEquals(finalPasswordHex) && x.getPasswordHash().contentEquals(finalPasswordHex) &&
(application == null || (application == null ||
(application == IntegryApplicationEnum.PVM && x.isWeb()) || (application == IntegryApplicationEnum.PVM && x.isWeb()) ||
(application == IntegryApplicationEnum.CONSEGNA && x.isWeb()) || (application == IntegryApplicationEnum.CONSEGNA && x.isWeb()) ||
(application == IntegryApplicationEnum.WMS && x.isWeb()) || (application == IntegryApplicationEnum.WMS && x.isWeb()) ||
(application == IntegryApplicationEnum.GESTIONALE_BASE && x.isInternal()))) (application == IntegryApplicationEnum.GESTIONALE_BASE && x.isInternal())))
.findFirst(); .findFirst();
//cacheLock.unlock(); return foundUser.orElse(null);
return foundUser.orElse(null); } finally {
cacheLock.unlock();
}
} }
public @Nullable UserDTO retrieveUserData(String profileDb, String username, IntegryApplicationEnum application) { public @Nullable UserDTO retrieveUserData(String profileDb, String username, IntegryApplicationEnum application) {
String dbName = settingsModel.getDbNameFromProfileDb(profileDb); cacheLock.lock();
try {
String dbName = settingsModel.getDbNameFromProfileDb(profileDb);
//cacheLock.lock(); List<UserDTO> users = cachedUsers.getOrDefault(dbName, null);
List<UserDTO> users = cachedUsers.getOrDefault(dbName, null);
if (users == null || users.isEmpty()) if (users == null || users.isEmpty())
return null; return null;
final Optional<UserDTO> foundUser = users.stream() final Optional<UserDTO> foundUser = users.stream()
.filter(x -> x.getUsername().equalsIgnoreCase(username) && .filter(x -> x.getUsername().equalsIgnoreCase(username) &&
(application == null || (application == null ||
(application == IntegryApplicationEnum.PVM && x.isWeb()) || (application == IntegryApplicationEnum.PVM && x.isWeb()) ||
(application == IntegryApplicationEnum.CONSEGNA && x.isWeb()) || (application == IntegryApplicationEnum.CONSEGNA && x.isWeb()) ||
(application == IntegryApplicationEnum.WMS && x.isWeb()) || (application == IntegryApplicationEnum.WMS && x.isWeb()) ||
(application == IntegryApplicationEnum.GESTIONALE_BASE && x.isInternal()))) (application == IntegryApplicationEnum.GESTIONALE_BASE && x.isInternal())))
.findFirst(); .findFirst();
//cacheLock.unlock();
return foundUser.orElse(null); return foundUser.orElse(null);
} finally {
cacheLock.unlock();
}
} }
public void discoverAllUsers(MultiDBTransactionManager multiDBTransactionManager) throws Exception { public void discoverAllUsers(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
//cacheLock.lock(); cacheLock.lock();
List<Callable<Void>> calls = new ArrayList<>(); try {
List<Callable<Void>> calls = new ArrayList<>();
for (final AdvancedDataSource advancedDataSource : multiDBTransactionManager.getActiveConnections()) { for (final AdvancedDataSource advancedDataSource : multiDBTransactionManager.getActiveConnections()) {
calls.add(() -> { calls.add(() -> {
try { try {
Connection conn = advancedDataSource.getConnection(); Connection conn = advancedDataSource.getConnection();
String sql = "SELECT su.user_name,\n" + String sql = "SELECT su.user_name,\n" +
" dbo.sys_dcd_pss(su.password) AS password, \n" + " dbo.sys_dcd_pss(su.password) AS password, \n" +
" CONVERT(varchar(max), HASHBYTES('SHA2_512', UPPER(dbo.sys_dcd_pss(su.password))),2) AS password_hash,\n" + " CONVERT(varchar(max), HASHBYTES('SHA2_512', UPPER(dbo.sys_dcd_pss(su.password))),2) AS password_hash,\n" +
" su.key_group,\n" + " su.key_group,\n" +
" su.full_name,\n" + " su.full_name,\n" +
" su.e_mail,\n" + " su.e_mail,\n" +
" su.last_access_datetime,\n" + " su.last_access_datetime,\n" +
" su.password_endtime,\n" + " su.password_endtime,\n" +
" CAST(IIF(su.destruction_datetime IS NOT NULL AND\n" + " CAST(IIF(su.destruction_datetime IS NOT NULL AND\n" +
" DATEDIFF(DAY, su.destruction_datetime, GETDATE()) > 0 AND su.flag_password_expiring = 'S', 1,\n" + " DATEDIFF(DAY, su.destruction_datetime, GETDATE()) > 0 AND su.flag_password_expiring = 'S', 1,\n" +
" 0) AS BIT) AS is_password_expired,\n" + " 0) AS BIT) AS is_password_expired,\n" +
" IIF(su.key_group = '3' AND su.user_code IS NULL, wc.cod_anag, su.user_code) AS user_code,\n" + " IIF(su.key_group = '3' AND su.user_code IS NULL, wc.cod_anag, su.user_code) AS user_code,\n" +
" wd.cod_mdep,\n" + " wd.cod_mdep,\n" +
" CAST(IIF(ISNULL(su.flag_attivo, 'N') = 'S', 1, 0) AS BIT) AS is_attivo,\n" + " CAST(IIF(ISNULL(su.flag_attivo, 'N') = 'S', 1, 0) AS BIT) AS is_attivo,\n" +
" CAST(IIF(su.flag_intra_user = 'S' OR su.flag_dba = 'S', 1, 0) AS BIT) AS is_internal,\n" + " CAST(IIF(su.flag_intra_user = 'S' OR su.flag_dba = 'S', 1, 0) AS BIT) AS is_internal,\n" +
" CAST(IIF(su.flag_intra_user = 'S' OR su.flag_extra_user = 'S', 1, 0) AS BIT) AS is_web\n" + " CAST(IIF(su.flag_intra_user = 'S' OR su.flag_extra_user = 'S', 1, 0) AS BIT) AS is_web\n" +
"FROM " + StbUser.ENTITY + " su " + "FROM " + StbUser.ENTITY + " su " +
" LEFT OUTER JOIN wtb_clie wc ON su.user_name = wc.user_name\n" + " LEFT OUTER JOIN wtb_clie wc ON su.user_name = wc.user_name\n" +
" LEFT OUTER JOIN wtb_depo wd ON su.user_name = wd.user_name\n" + " LEFT OUTER JOIN wtb_depo wd ON su.user_name = wd.user_name\n" +
" LEFT OUTER JOIN mtb_depo md ON wd.cod_mdep = md.cod_mdep\n" + " LEFT OUTER JOIN mtb_depo md ON wd.cod_mdep = md.cod_mdep\n" +
"WHERE dbo.sys_dcd_pss(su.password) IS NOT NULL"; "WHERE dbo.sys_dcd_pss(su.password) IS NOT NULL";
final List<UserDTO> userDTOS = UtilityDB.executeSimpleQueryDTO(conn, sql, UserDTO.class); final List<UserDTO> userDTOS = UtilityDB.executeSimpleQueryDTO(conn, sql, UserDTO.class);
if (userDTOS != null) if (userDTOS != null)
userDTOS.forEach(x -> cache(advancedDataSource.getDataSource().getDbName(), x)); userDTOS.forEach(x -> cache(advancedDataSource.getDataSource().getDbName(), x));
} catch (Exception ex) { } catch (Exception ex) {
logger.error(String.format("Errore durante la retrieve degli utenti su \"%s\". %s", advancedDataSource.getProfileName(), ex.getMessage()), ex); logger.error(String.format("Errore durante la retrieve degli utenti su \"%s\". %s", advancedDataSource.getProfileName(), ex.getMessage()), ex);
} }
return null; return null;
}); });
}
taskExecutorService.executeTasks(calls);
} finally {
cacheLock.unlock();
} }
taskExecutorService.executeTasks(calls);
//cacheLock.unlock();
} }
public void invalidateCache() { public void invalidateCache() {
//cacheLock.lock(); cacheLock.lock();
this.cachedUsers.clear(); this.cachedUsers.clear();
//cacheLock.unlock(); cacheLock.unlock();
this.internalCacheUpdate(); this.internalCacheUpdate();
} }