From 3ef5dea4a4176296e8e50ca1f9d651bcd88e3b90 Mon Sep 17 00:00:00 2001 From: zyyang Date: Wed, 27 Jan 2021 14:29:13 +0800 Subject: [PATCH] change --- .../taosdata/example/ConnectionPoolDemo.java | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/example/ConnectionPoolDemo.java b/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/example/ConnectionPoolDemo.java index 7b603ec97f..3b288b38dc 100644 --- a/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/example/ConnectionPoolDemo.java +++ b/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/example/ConnectionPoolDemo.java @@ -1,5 +1,6 @@ package com.taosdata.example; +import com.taosdata.example.common.InsertTask; import com.taosdata.example.pool.C3p0Builder; import com.taosdata.example.pool.DbcpBuilder; import com.taosdata.example.pool.DruidPoolBuilder; @@ -10,6 +11,9 @@ import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; public class ConnectionPoolDemo { @@ -31,12 +35,16 @@ public class ConnectionPoolDemo { if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1) { host = args[++i]; } + if ("-recordNumber".equalsIgnoreCase(args[i]) && i < args.length - 1) { + totalSize = Long.parseLong(args[++i]); + } if ("-poolType".equalsIgnoreCase(args[i]) && i < args.length - 1) { poolType = args[++i]; } + } if (host == null) { - System.out.println("Usage: java -jar XXX.jar -host -poolType "); + System.out.println("Usage: java -jar XXX.jar -host -recordNumber -poolType "); return; } @@ -60,31 +68,31 @@ public class ConnectionPoolDemo { logger.info(">>>>>>>>>>>>>> connection pool Type: " + poolType); init(dataSource); - try { - Connection connection = dataSource.getConnection(); - Statement statement = connection.createStatement(); - String sql = "insert into " + dbName + ".t_1 values('2020-01-01 00:00:00.000',12.12,111)"; - int affectRows = statement.executeUpdate(sql); - System.out.println("affectRows >>> " + affectRows); - affectRows = statement.executeUpdate(sql); - System.out.println("affectRows >>> " + affectRows); - statement.close(); - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - -// ExecutorService executor = Executors.newFixedThreadPool(threadCount); -// for (long i = 0; i < totalSize / batchSize / tableSize; i++) { -// executor.execute(new InsertTask(dataSource, dbName, tableSize, batchSize)); -// // sleep few seconds -// try { -// TimeUnit.MILLISECONDS.sleep(sleep); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } +// try { +// Connection connection = dataSource.getConnection(); +// Statement statement = connection.createStatement(); +// String sql = "insert into " + dbName + ".t_1 values('2020-01-01 00:00:00.000',12.12,111)"; +// int affectRows = statement.executeUpdate(sql); +// System.out.println("affectRows >>> " + affectRows); +// affectRows = statement.executeUpdate(sql); +// System.out.println("affectRows >>> " + affectRows); +// statement.close(); +// connection.close(); +// } catch (SQLException e) { +// e.printStackTrace(); // } -// executor.shutdown(); + + ExecutorService executor = Executors.newFixedThreadPool(threadCount); + for (long i = 0; i < totalSize / batchSize / tableSize; i++) { + executor.execute(new InsertTask(dataSource, dbName, tableSize, batchSize)); + // sleep few seconds + try { + TimeUnit.MILLISECONDS.sleep(sleep); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + executor.shutdown(); } -- GitLab