Linliangkung opened a new issue #9115:
URL: https://github.com/apache/shardingsphere/issues/9115


   AbstractConnectionAdapter.createConnections方法(问题描述在代码块注释中)
   ``` java
   private List<Connection> createConnections(final String dataSourceName, 
final ConnectionMode connectionMode, final DataSource dataSource, final int 
connectionSize) throws SQLException {
           if (1 == connectionSize) {
               Connection connection = createConnection(dataSourceName, 
dataSource);
               replayMethodsInvocation(connection);
               return Collections.singletonList(connection);
           }
           if (ConnectionMode.CONNECTION_STRICTLY == connectionMode) {
               //CONNECTION_STRICTLY 模式下为什么没有加synchronized代码块
              //假设我的connectionSize为2,数据源最大线程数是2
              //现在有两个线程A和线程B同时执行下面的createConnections方法
              //如果线程A和线程B都同时拿到一个连接,然后再去拿第二个连接的时候就会出现占有一个连接,相互等待对方释放连接的情况出现
               return createConnections(dataSourceName, dataSource, 
connectionSize);
           }
           synchronized (dataSource) {
               return createConnections(dataSourceName, dataSource, 
connectionSize);
           }
       } 
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to