Merge branch 'master' into develop
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -13,10 +13,12 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Component
|
||||
public class BasicConnectionPool {
|
||||
@@ -29,26 +31,26 @@ public class BasicConnectionPool {
|
||||
@Autowired
|
||||
private SettingsModel settingsModel;
|
||||
|
||||
private final Map<String, List<DataSource>> connectionPool = new ConcurrentHashMap<>();
|
||||
private final Map<String, List<DataSource>> usedConnections = new ConcurrentHashMap<>();
|
||||
private final Map<String, AtomicInteger> extraConnectionCounters = new ConcurrentHashMap<>();
|
||||
private final Map<String, Set<String>> activeConnectionNames = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, List<DataSource>> connectionPool = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, List<DataSource>> usedConnections = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, AtomicInteger> extraConnectionCounters = 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 {
|
||||
poolLock.lock();
|
||||
// poolLock.lock();
|
||||
try {
|
||||
closeAllConnections();
|
||||
int poolSize = calculatePoolSize();
|
||||
initializeConnections(poolSize);
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
// poolLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeAllConnections() {
|
||||
poolLock.lock();
|
||||
// poolLock.lock();
|
||||
try {
|
||||
// Chiude tutte le connessioni esistenti
|
||||
connectionPool.values().forEach(connections ->
|
||||
@@ -62,7 +64,7 @@ public class BasicConnectionPool {
|
||||
extraConnectionCounters.clear();
|
||||
activeConnectionNames.clear();
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
// poolLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +134,7 @@ public class BasicConnectionPool {
|
||||
return null;
|
||||
}
|
||||
|
||||
poolLock.lock();
|
||||
// poolLock.lock();
|
||||
try {
|
||||
if (!connectionPool.containsKey(dbName) || connectionPool.get(dbName).isEmpty()) {
|
||||
return createExtraConnection(profileName);
|
||||
@@ -157,7 +159,7 @@ public class BasicConnectionPool {
|
||||
logger.trace("Assigned connection: {} for database: {}", ds.getApplicationName(), dbName);
|
||||
return ds;
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
// poolLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +169,7 @@ public class BasicConnectionPool {
|
||||
return false;
|
||||
}
|
||||
|
||||
poolLock.lock();
|
||||
// poolLock.lock();
|
||||
try {
|
||||
String currentCatalog = ds.getConnection().getCatalog();
|
||||
AvailableConnectionsModel model = findConnectionModel(profileName);
|
||||
@@ -183,13 +185,13 @@ public class BasicConnectionPool {
|
||||
|
||||
return handleConnectionRelease(ds);
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
// poolLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private DataSource createExtraConnection(String profileName) throws Exception {
|
||||
String dbName = settingsModel.getDbNameFromProfileDb(profileName);
|
||||
poolLock.lock();
|
||||
// poolLock.lock();
|
||||
try {
|
||||
// Calcola il numero totale di connessioni esistenti
|
||||
int baseCount = connectionPool.get(dbName).size() + usedConnections.get(dbName).size();
|
||||
@@ -211,7 +213,7 @@ public class BasicConnectionPool {
|
||||
logger.trace("Created extra connection: {} for database: {}", connectionName, dbName);
|
||||
return ds;
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
// poolLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user