From b0c7a36e7370ac92a1b514d378ab502168ac310a Mon Sep 17 00:00:00 2001 From: zyyang Date: Mon, 1 Feb 2021 13:02:12 +0800 Subject: [PATCH] change --- src/connector/jdbc/pom.xml | 2 +- .../com/taosdata/jdbc/TSDBJNIConnector.java | 13 ++----- .../java/com/taosdata/jdbc/TSDBStatement.java | 6 ++- .../com/taosdata/jdbc/utils/TaosInfo.java | 39 ++++++++++++++----- .../taosdata/jdbc/utils/TaosInfoMBean.java | 9 ++++- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 5ca5e96a84..0626bcf1fb 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -123,7 +123,7 @@ maven-surefire-plugin 2.12.4 - pretest + pertest ${maven.test.jvmargs} **/*Test.java diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index 9b387b1959..349a02fb37 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -16,9 +16,6 @@ package com.taosdata.jdbc; import com.taosdata.jdbc.utils.TaosInfo; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import java.lang.management.ManagementFactory; import java.sql.SQLException; import java.sql.SQLWarning; import java.util.List; @@ -31,7 +28,6 @@ public class TSDBJNIConnector { static { System.loadLibrary("taos"); System.out.println("java.library.path:" + System.getProperty("java.library.path")); - } /** @@ -109,9 +105,7 @@ public class TSDBJNIConnector { throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg(0L)), "", this.getErrCode(0l)); } // invoke connectImp only here - int open = taosInfo.getOpen_count().incrementAndGet(); - int close = taosInfo.getClose_count().get(); - System.out.println("open_count: " + open + ", close_count: " + close + ", connection_count: " + (taosInfo.getConnectionCount())); + taosInfo.conn_open_increment(); return true; } @@ -132,6 +126,7 @@ public class TSDBJNIConnector { Long pSql = 0l; try { pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos); + taosInfo.stmt_count_increment(); } catch (Exception e) { e.printStackTrace(); this.freeResultSetImp(this.taos, pSql); @@ -276,9 +271,7 @@ public class TSDBJNIConnector { throw new SQLException("Undefined error code returned by TDengine when closing a connection"); } // invoke closeConnectionImpl only here - int open = taosInfo.getOpen_count().get(); - int close = taosInfo.getClose_count().incrementAndGet(); - System.out.println("open_count: " + open + ", close_count: " + close + ", connection_count: " + (taosInfo.getConnectionCount())); + taosInfo.connect_close_increment(); } private native int closeConnectionImp(long connection); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index e7317b8e1d..402d114215 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -14,13 +14,15 @@ *****************************************************************************/ package com.taosdata.jdbc; +import com.taosdata.jdbc.utils.TaosInfo; + import java.sql.*; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; public class TSDBStatement implements Statement { - private TSDBJNIConnector connector = null; + private TSDBJNIConnector connector; + private TaosInfo taosInfo = TaosInfo.getInstance(); /** * To store batched commands diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java index 83ac7ed809..69a90fe3b3 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java @@ -3,12 +3,14 @@ package com.taosdata.jdbc.utils; import javax.management.*; import java.lang.management.ManagementFactory; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; public class TaosInfo implements TaosInfoMBean { private static volatile TaosInfo instance; - private AtomicInteger open_count = new AtomicInteger(); - private AtomicInteger close_count = new AtomicInteger(); + private AtomicLong connect_open = new AtomicLong(); + private AtomicLong connect_close = new AtomicLong(); + private AtomicLong statement_count = new AtomicLong(); static { try { @@ -21,23 +23,40 @@ public class TaosInfo implements TaosInfoMBean { } @Override - public int getConnectionCount() { - return open_count.get() - close_count.get(); + public long getConnect_open() { + return connect_open.get(); } @Override - public int getStatementCount() { - return 0; + public long getConnect_close() { + return connect_close.get(); } - public AtomicInteger getOpen_count() { - return open_count; + @Override + public long getConnect_active() { + return connect_open.get() - connect_close.get(); + } + + @Override + public long getStatement_count() { + return statement_count.get(); + } + + /*******************************************************/ + + public void conn_open_increment() { + connect_open.incrementAndGet(); + } + + public void connect_close_increment() { + connect_close.incrementAndGet(); } - public AtomicInteger getClose_count() { - return close_count; + public void stmt_count_increment() { + statement_count.incrementAndGet(); } + /********************************************************************************/ private TaosInfo() { } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfoMBean.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfoMBean.java index 791292e902..e16f41b2f5 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfoMBean.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfoMBean.java @@ -2,7 +2,12 @@ package com.taosdata.jdbc.utils; public interface TaosInfoMBean { - int getConnectionCount(); + long getConnect_open(); + + long getConnect_close(); + + long getConnect_active(); + + long getStatement_count(); - int getStatementCount(); } -- GitLab