diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 5ca5e96a84157def62292756c4949bbe2c904500..0626bcf1fb1161cc38ad05002b984b2200b68d68 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 9b387b1959ba032aa9a84f5ad70bcebbbe3d0649..349a02fb37c28b263bb73bcc05f644bc53f71079 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 e7317b8e1d6eb2744c50a5bf1d106c7b687cc965..402d114215535a517c02c16796ebe4ba7705a741 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 83ac7ed809d9d864ba55fc9d79a2306013602421..69a90fe3b378067eda6de0efb2b655d41c49a1da 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 791292e902903f137811699b22b02dd3248983e5..e16f41b2f585244721e923a963c53fb6b7bccf47 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(); }