TeslaCN commented on issue #12309:
URL: 
https://github.com/apache/shardingsphere/issues/12309#issuecomment-970181485


   I found a way to reproduce this issue:
   
   ```java
   package icu.wwj.hello.jdbc;
   
   import lombok.SneakyThrows;
   
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.PreparedStatement;
   import java.sql.Types;
   import java.util.concurrent.SynchronousQueue;
   import java.util.concurrent.ThreadLocalRandom;
   import java.util.concurrent.ThreadPoolExecutor;
   import java.util.concurrent.TimeUnit;
   
   public class MySQLRepeatedlyPrepareExecuteClose {
       
       public static void main(String[] args) {
           final int threads = 2;
           Runnable runnable = () -> {
               try (Connection connection = getConnection()) {
                   for (; ; ) {
                       try (PreparedStatement preparedStatement = 
connection.prepareStatement("select * from sbtest1 where id = ?")) {
                           int result = 
ThreadLocalRandom.current().nextInt(200000);
                           if (result > 100000) {
                               preparedStatement.setNull(1, Types.INTEGER);
                           } else {
                               preparedStatement.setInt(1, result);
                           }
                           preparedStatement.executeQuery().close();
                       }
                   }
               } catch (Exception ex) {
                   ex.printStackTrace();
               }
           };
           ThreadPoolExecutor executor = new ThreadPoolExecutor(threads, 
threads, 0L, TimeUnit.SECONDS, new SynchronousQueue<>());
           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/sbtest_direct?useSSL=false&useServerPrepStmts=true&cachePrepStmts=false&prepStmtCacheSize=1",
 "root", "root");
       }
   }
   ```


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