TeslaCN edited a comment on issue #16294:
URL: 
https://github.com/apache/shardingsphere/issues/16294#issuecomment-1080198856


   Closing 100 prepared statements once is easier to reproduce this issue.
   
   ```
   package icu.wwj.hello.jdbc;
   
   import lombok.SneakyThrows;
   
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.Statement;
   import java.util.concurrent.CyclicBarrier;
   import java.util.concurrent.ExecutorService;
   import java.util.concurrent.Executors;
   
   public class MySQLProxyPreparedStatement {
       
       public static void main(String[] args) throws Exception {
           int threads = 32;
           CyclicBarrier barrier = new CyclicBarrier(threads);
           Runnable runnable = () -> {
               try (Connection connection = getConnection(); Statement 
statement = connection.createStatement()) {
                   connection.setAutoCommit(false);
                   barrier.await();
                   for (int i = 0; i < 100; i++) {
                       PreparedStatement[] preparedStatements = new 
PreparedStatement[100];
                       for (int i1 = 0; i1 < preparedStatements.length; i1++) {
                           preparedStatements[i1] = 
connection.prepareStatement("select * from bmsql_item where i_id = ?");
                           preparedStatements[i1].setInt(1, i + 1);
                           try (ResultSet resultSet = 
preparedStatements[i1].executeQuery()) {
                               while (resultSet.next()) {
                                   resultSet.getInt(1);
                               }
                           }
                       }
                       for (PreparedStatement each : preparedStatements) {
                           each.close();
                       }
                       try (ResultSet resultSet = 
statement.executeQuery("select 1")) {
                           while (resultSet.next()) {
                               resultSet.getInt(1);
                           }
                       }
                   }
                   connection.rollback();
               } catch (Exception ex) {
                   ex.printStackTrace();
               }
           };
           ExecutorService executor = Executors.newFixedThreadPool(threads);
           for (int i = 0; i < threads; i++) {
               executor.execute(runnable);
           }
           executor.shutdown();
       }
       
       @SneakyThrows
       private static Connection getConnection() {
           return 
DriverManager.getConnection("jdbc:mysql://127.0.0.1:13306/bmsql_sharding?useSSL=false&useServerPrepStmts=true&cachePrepStmts=false",
 "root", "root");
   //        return 
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/bmsql?useSSL=false&useServerPrepStmts=true&cachePrepStmts=false",
 "root", "root");
       }
   }
   ```
   
   
![image](https://user-images.githubusercontent.com/20503072/160330310-0a0035af-263d-49b9-a8ef-1816b9f9042e.png)
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to