diff --git a/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java index 4ab92a91f50820ab005702c8ddc56bf2e7f198f0..eca321c6ee914f86ce8002418d751ef55a6b0e7d 100644 --- a/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java +++ b/src/main/java/com/beagle/informix/service/impl/InformixJdbcProxyServiceImpl.java @@ -11,6 +11,10 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.sql.*; import java.util.Properties; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * @author lzz @@ -40,16 +44,44 @@ public class InformixJdbcProxyServiceImpl implements InformixService { */ @Override public void doConnectJob() throws Exception{ - // todo 使用jdbc连接proxy,对应的query(clob、blob字段)存在jdbc 类型转换mysql异常的问题 +// // todo 使用jdbc连接proxy,对应的query(clob、blob字段)存在jdbc 类型转换mysql异常的问题 +// // Unknown exception: Can not find JDBC type `2005` in column type +// Driver driver = getDriver(); +// Connection conn = getConnection(driver); +// insert(conn); +//// update(conn); +//// query(conn); +//// delete(conn); +// closeConnection(conn); +// deregisterDriver(driver); // Unknown exception: Can not find JDBC type `2005` in column type - Driver driver = getDriver(); - Connection conn = getConnection(driver); - insert(conn); -// update(conn); -// query(conn); -// delete(conn); - closeConnection(conn); - deregisterDriver(driver); + CompletableFuture completableFuture = new CompletableFuture<>(); + ExecutorService executorService = Executors.newFixedThreadPool(500); + for (int i = 0; i < 500; i++) { + try { + Driver driver = getDriver(); + Connection conn = getConnection(driver); + completableFuture.runAsync(()->{ + try { + query(conn); + }catch (Exception ee) { + ee.printStackTrace(); + } + }, executorService).whenComplete((v, e) -> { + if (e != null) { + e.printStackTrace(); + } + try { + closeConnection(conn); + deregisterDriver(driver); + }catch (Exception ex) { + ex.printStackTrace(); + } + }); + } catch (Exception e) { + throw new RuntimeException(e); + } + } } private Driver getDriver() throws Exception{ // 定义informix的驱动信息 @@ -94,28 +126,13 @@ public class InformixJdbcProxyServiceImpl implements InformixService { stat.executeUpdate(); } private void query(Connection conn) throws Exception { - String querySQL = "select * from cti_vccinfo_new where vccid = '123456' "; + String querySQL = "SELECT id FROM sc_test "; PreparedStatement stat = conn.prepareStatement(querySQL); ResultSet resultSet = stat.executeQuery(); - if (resultSet != null) { - while (resultSet.next()) { - log.info("vccid =>" + resultSet.getString("vccid")); - Clob clob = resultSet.getClob("tclob"); - BufferedReader reader = new BufferedReader(clob.getCharacterStream()); - String clobStr = ""; - String finalClobStr = ""; - while ((clobStr = reader.readLine())!= null) { - finalClobStr += clobStr; - } - log.info("tclob =>" + finalClobStr); - Blob blob = resultSet.getBlob("tblob"); - BufferedInputStream bins= new BufferedInputStream(blob.getBinaryStream()); - byte [] bytes = bins.readAllBytes(); - String blobStr= new String(bytes, StandardCharsets.UTF_8); - log.info("tblob =>" + blobStr); - } - } } + + + private void delete(Connection conn) throws Exception{ String deleteSql = "delete from cti_vccinfo_new where vccid = '123456' "; conn.createStatement().executeUpdate(deleteSql); @@ -125,9 +142,10 @@ public class InformixJdbcProxyServiceImpl implements InformixService { Properties properties = new Properties(); // 组装连接数据库信息 // jdbc:informix-sqli://:/:informixserver= - StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307") - .append("/") - .append("testdb").append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); + StringBuilder jdbcBuilder = new StringBuilder("jdbc:mysql://localhost:3307"); +// .append("/") +// .append("SYSDBA") +// .append("?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true"); DriverManager.setLoginTimeout(10); properties.put("user", "root"); properties.put("password", "Apurelove9014"); @@ -136,4 +154,7 @@ public class InformixJdbcProxyServiceImpl implements InformixService { private void closeConnection(Connection connection) throws Exception { connection.close(); } + + + } diff --git a/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java b/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java index 085b5357db29e9ae0100b46d4bb19dd82a890d97..8288c278653f1f162258ca77e011707592501e92 100644 --- a/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java +++ b/src/main/java/com/beagle/informix/service/impl/InformixMybatisServiceImpl.java @@ -17,7 +17,12 @@ import javax.annotation.Resource; import javax.transaction.Transactional; import java.io.File; import java.io.FileInputStream; +import java.sql.Connection; +import java.sql.Driver; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * @author lzz @@ -35,10 +40,22 @@ public class InformixMybatisServiceImpl extends ServiceImpl(); + ExecutorService executorService = Executors.newFixedThreadPool(500); + for (int i = 0; i < 500; i++) { + try { + + completableFuture.runAsync(()->{ + queryMethod(); + }, executorService).whenComplete((v, e) -> { + if (e != null) { + e.printStackTrace(); + } + }); + } catch (Exception e) { + throw new RuntimeException(e); + } + } } private void insertMethod() throws Exception{ Vccinfo vccinfo = new Vccinfo(); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 2b2ede3bf591a1a7eacd38521aa777e4164cdabc..9dfc044dfe18f17e509b4c8c1c165ece7b977be1 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,26 +1,24 @@ spring: datasource: - druid: -# url: jdbc:informix-sqli://localhost:9088/testdb:INFORMIXSERVER=informix - #&useServerPrepStmts=true # url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai - url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai + url: jdbc:mysql://localhost:3307 +# url: jdbc:mysql://localhost:3307/SYSDBA?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai # url: jdbc:mysql://localhost:3307/testdb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&useServerPrepStmts=true username: root -# username: informix -# password: in4mix password: Apurelove9014 -# max-active: 20 -# max-wait: 60000 -# initial-size: 5 -# connect-timeout: 30 -# min-idle: 5 -# min-evictable-idle-time-millis: 300000 -# validation-query: select 1 -# test-on-borrow: false -# test-on-return: false -# test-while-idle: false -# time-between-eviction-runs-millis: 60000 + type: com.alibaba.druid.pool.DruidDataSource + druid: + max-active: 500 + max-wait: 60000 + initial-size: 500 + connect-timeout: 30 + min-idle: 500 + min-evictable-idle-time-millis: 300000 + validation-query: select 1 + test-on-borrow: false + test-on-return: false + test-while-idle: false + time-between-eviction-runs-millis: 60000 # driver-class-name: com.informix.jdbc.IfxDriver driver-class-name: com.mysql.jdbc.Driver # com.mysql.cj.jdbc.Driver jpa: