Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
72700141
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
72700141
编写于
1月 29, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
d12b77ce
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
13 deletion
+51
-13
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+11
-9
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java
.../jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java
+40
-4
未找到文件。
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
72700141
...
@@ -16,20 +16,22 @@ package com.taosdata.jdbc;
...
@@ -16,20 +16,22 @@ package com.taosdata.jdbc;
import
com.taosdata.jdbc.utils.TaosInfo
;
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.SQLException
;
import
java.sql.SQLWarning
;
import
java.sql.SQLWarning
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.atomic.AtomicInteger
;
public
class
TSDBJNIConnector
{
public
class
TSDBJNIConnector
{
private
static
volatile
Boolean
isInitialized
=
false
;
private
static
volatile
Boolean
isInitialized
=
false
;
private
static
AtomicInteger
open_count
=
new
AtomicInteger
();
private
TaosInfo
taosInfo
=
TaosInfo
.
getInstance
();
private
static
AtomicInteger
close_count
=
new
AtomicInteger
();
static
{
static
{
System
.
loadLibrary
(
"taos"
);
System
.
loadLibrary
(
"taos"
);
System
.
out
.
println
(
"java.library.path:"
+
System
.
getProperty
(
"java.library.path"
));
System
.
out
.
println
(
"java.library.path:"
+
System
.
getProperty
(
"java.library.path"
));
}
}
/**
/**
...
@@ -107,9 +109,9 @@ public class TSDBJNIConnector {
...
@@ -107,9 +109,9 @@ public class TSDBJNIConnector {
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
this
.
getErrMsg
(
0L
)),
""
,
this
.
getErrCode
(
0
l
));
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
this
.
getErrMsg
(
0L
)),
""
,
this
.
getErrCode
(
0
l
));
}
}
// invoke connectImp only here
// invoke connectImp only here
int
open
=
open_count
.
incrementAndGet
();
int
open
=
taosInfo
.
getOpen_count
()
.
incrementAndGet
();
int
close
=
close_count
.
get
();
int
close
=
taosInfo
.
getClose_count
()
.
get
();
System
.
out
.
println
(
"open_count: "
+
open
+
", close_count: "
+
close
+
", connection_count: "
+
(
open
-
close
));
System
.
out
.
println
(
"open_count: "
+
open
+
", close_count: "
+
close
+
", connection_count: "
+
(
taosInfo
.
getConnectionCount
()
));
return
true
;
return
true
;
}
}
...
@@ -274,9 +276,9 @@ public class TSDBJNIConnector {
...
@@ -274,9 +276,9 @@ public class TSDBJNIConnector {
throw
new
SQLException
(
"Undefined error code returned by TDengine when closing a connection"
);
throw
new
SQLException
(
"Undefined error code returned by TDengine when closing a connection"
);
}
}
// invoke closeConnectionImpl only here
// invoke closeConnectionImpl only here
int
open
=
open_count
.
get
();
int
open
=
taosInfo
.
getOpen_count
()
.
get
();
int
close
=
close_count
.
incrementAndGet
();
int
close
=
taosInfo
.
getClose_count
()
.
incrementAndGet
();
System
.
out
.
println
(
"open_count: "
+
open
+
", close_count: "
+
close
+
", connection_count: "
+
(
open
-
close
));
System
.
out
.
println
(
"open_count: "
+
open
+
", close_count: "
+
close
+
", connection_count: "
+
(
taosInfo
.
getConnectionCount
()
));
}
}
private
native
int
closeConnectionImp
(
long
connection
);
private
native
int
closeConnectionImp
(
long
connection
);
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java
浏览文件 @
72700141
package
com.taosdata.jdbc.utils
;
package
com.taosdata.jdbc.utils
;
import
javax.management.*
;
import
java.lang.management.ManagementFactory
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
public
class
TaosInfo
implements
TaosInfoMBean
{
public
class
TaosInfo
implements
TaosInfoMBean
{
public
AtomicInteger
conn
=
new
AtomicInteger
();
private
static
volatile
TaosInfo
instance
;
public
AtomicInteger
stmt
=
new
AtomicInteger
();
private
AtomicInteger
open_count
=
new
AtomicInteger
();
private
AtomicInteger
close_count
=
new
AtomicInteger
();
static
{
try
{
MBeanServer
server
=
ManagementFactory
.
getPlatformMBeanServer
();
ObjectName
name
=
new
ObjectName
(
"TaosInfoMBean:name=TaosInfo"
);
server
.
registerMBean
(
TaosInfo
.
getInstance
(),
name
);
}
catch
(
MalformedObjectNameException
|
InstanceAlreadyExistsException
|
MBeanRegistrationException
|
NotCompliantMBeanException
e
)
{
e
.
printStackTrace
();
}
}
@Override
@Override
public
int
getConnectionCount
()
{
public
int
getConnectionCount
()
{
return
conn
.
get
();
return
open_count
.
get
()
-
close_count
.
get
();
}
}
@Override
@Override
public
int
getStatementCount
()
{
public
int
getStatementCount
()
{
return
stmt
.
get
();
return
0
;
}
public
AtomicInteger
getOpen_count
()
{
return
open_count
;
}
public
AtomicInteger
getClose_count
()
{
return
close_count
;
}
}
private
TaosInfo
()
{
}
public
static
TaosInfo
getInstance
()
{
if
(
instance
==
null
)
{
synchronized
(
TaosInfo
.
class
)
{
if
(
instance
==
null
)
{
instance
=
new
TaosInfo
();
}
}
}
return
instance
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录