Synchronized collection in connection pool
This commit is contained in:
16
.idea/runConfigurations/Tomcat_9__1__DBServer2019_.xml
generated
Normal file
16
.idea/runConfigurations/Tomcat_9__1__DBServer2019_.xml
generated
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Tomcat 9 #1 (DBServer2019)" type="Remote" folderName="Biolevante">
|
||||||
|
<module name="ims" />
|
||||||
|
<option name="USE_SOCKET_TRANSPORT" value="true" />
|
||||||
|
<option name="SERVER_MODE" value="false" />
|
||||||
|
<option name="SHMEM_ADDRESS" />
|
||||||
|
<option name="HOST" value="192.168.10.6" />
|
||||||
|
<option name="PORT" value="8001" />
|
||||||
|
<option name="AUTO_RESTART" value="false" />
|
||||||
|
<RunnerSettings RunnerId="Debug">
|
||||||
|
<option name="DEBUG_PORT" value="8001" />
|
||||||
|
<option name="LOCAL" value="false" />
|
||||||
|
</RunnerSettings>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -10,9 +10,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class BasicConnectionPool {
|
public class BasicConnectionPool {
|
||||||
@@ -20,8 +18,8 @@ public class BasicConnectionPool {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SettingsModel settingsModel;
|
private SettingsModel settingsModel;
|
||||||
|
|
||||||
private final HashMap<String, List<DataSource>> connectionPool = new HashMap<>();
|
private final Map<String, List<DataSource>> connectionPool = Collections.synchronizedMap(new HashMap<>());
|
||||||
private final HashMap<String, List<DataSource>> usedConnections = new HashMap<>();
|
private final Map<String, List<DataSource>> usedConnections = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
|
||||||
public synchronized void init() throws Exception {
|
public synchronized void init() throws Exception {
|
||||||
|
|
||||||
@@ -40,10 +38,10 @@ public class BasicConnectionPool {
|
|||||||
for (final AvailableConnectionsModel availableConnectionsModel : availableConnections) {
|
for (final AvailableConnectionsModel availableConnectionsModel : availableConnections) {
|
||||||
synchronized (connectionPool) {
|
synchronized (connectionPool) {
|
||||||
if (!connectionPool.containsKey(availableConnectionsModel.getProfileName()))
|
if (!connectionPool.containsKey(availableConnectionsModel.getProfileName()))
|
||||||
connectionPool.put(availableConnectionsModel.getProfileName(), new ArrayList<>());
|
connectionPool.put(availableConnectionsModel.getProfileName(), Collections.synchronizedList(new ArrayList<>()));
|
||||||
|
|
||||||
if (!usedConnections.containsKey(availableConnectionsModel.getProfileName()))
|
if (!usedConnections.containsKey(availableConnectionsModel.getProfileName()))
|
||||||
usedConnections.put(availableConnectionsModel.getProfileName(), new ArrayList<>());
|
usedConnections.put(availableConnectionsModel.getProfileName(), Collections.synchronizedList(new ArrayList<>()));
|
||||||
|
|
||||||
int createdConnections = connectionPool.get(availableConnectionsModel.getProfileName()).size() +
|
int createdConnections = connectionPool.get(availableConnectionsModel.getProfileName()).size() +
|
||||||
usedConnections.get(availableConnectionsModel.getProfileName()).size();
|
usedConnections.get(availableConnectionsModel.getProfileName()).size();
|
||||||
|
|||||||
Reference in New Issue
Block a user