Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7e75e5ca
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7e75e5ca
编写于
11月 27, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
36236474
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
24 addition
and
11 deletion
+24
-11
tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
...s/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
+17
-11
tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/pool/HikariCpBuilder.java
...src/main/java/com/taosdata/demo/pool/HikariCpBuilder.java
+7
-0
未找到文件。
tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
浏览文件 @
7e75e5ca
...
@@ -13,6 +13,7 @@ import java.sql.SQLException;
...
@@ -13,6 +13,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
public
class
ConnectionPoolDemo
{
public
class
ConnectionPoolDemo
{
...
@@ -22,9 +23,9 @@ public class ConnectionPoolDemo {
...
@@ -22,9 +23,9 @@ public class ConnectionPoolDemo {
private
static
int
batchSize
=
10
;
private
static
int
batchSize
=
10
;
private
static
int
sleep
=
1000
;
private
static
int
sleep
=
1000
;
private
static
int
p
oolSize
=
50
;
private
static
int
connectionP
oolSize
=
50
;
private
static
int
tableSize
=
1000
;
private
static
int
tableSize
=
1000
;
private
static
int
thread
Count
=
50
;
private
static
int
thread
PoolSize
=
50
;
private
static
String
poolType
=
"hikari"
;
private
static
String
poolType
=
"hikari"
;
...
@@ -40,8 +41,8 @@ public class ConnectionPoolDemo {
...
@@ -40,8 +41,8 @@ public class ConnectionPoolDemo {
if
(
"-sleep"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
if
(
"-sleep"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
sleep
=
Integer
.
parseInt
(
args
[++
i
]);
sleep
=
Integer
.
parseInt
(
args
[++
i
]);
}
}
if
(
"-
p
oolSize"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
if
(
"-
connectP
oolSize"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
p
oolSize
=
Integer
.
parseInt
(
args
[++
i
]);
connectionP
oolSize
=
Integer
.
parseInt
(
args
[++
i
]);
}
}
if
(
"-tableSize"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
if
(
"-tableSize"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
tableSize
=
Integer
.
parseInt
(
args
[++
i
]);
tableSize
=
Integer
.
parseInt
(
args
[++
i
]);
...
@@ -49,14 +50,18 @@ public class ConnectionPoolDemo {
...
@@ -49,14 +50,18 @@ public class ConnectionPoolDemo {
if
(
"-poolType"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
if
(
"-poolType"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
poolType
=
args
[++
i
];
poolType
=
args
[++
i
];
}
}
if
(
"-threadPoolSize"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
threadPoolSize
=
Integer
.
parseInt
(
args
[++
i
]);
}
}
}
if
(
host
==
null
)
{
if
(
host
==
null
)
{
System
.
out
.
println
(
"Usage: java -jar XXX.jar "
+
System
.
out
.
println
(
"Usage: java -jar XXX.jar "
+
"-host <hostname> "
+
"-host <hostname> "
+
"-batchSize <batchSize> "
+
"-batchSize <batchSize> "
+
"-sleep <sleep> "
+
"-sleep <sleep> "
+
"-
poolSize <p
oolSize> "
+
"-
connectionPoolSize <connectionP
oolSize> "
+
"-tableSize <tableSize>"
+
"-tableSize <tableSize>"
+
"-threadPoolSize <threadPoolSize>"
+
"-poolType <c3p0| dbcp| druid| hikari>"
);
"-poolType <c3p0| dbcp| druid| hikari>"
);
return
;
return
;
}
}
...
@@ -64,33 +69,34 @@ public class ConnectionPoolDemo {
...
@@ -64,33 +69,34 @@ public class ConnectionPoolDemo {
DataSource
dataSource
;
DataSource
dataSource
;
switch
(
poolType
)
{
switch
(
poolType
)
{
case
"c3p0"
:
case
"c3p0"
:
dataSource
=
C3p0Builder
.
getDataSource
(
host
,
p
oolSize
);
dataSource
=
C3p0Builder
.
getDataSource
(
host
,
connectionP
oolSize
);
break
;
break
;
case
"dbcp"
:
case
"dbcp"
:
dataSource
=
DbcpBuilder
.
getDataSource
(
host
,
p
oolSize
);
dataSource
=
DbcpBuilder
.
getDataSource
(
host
,
connectionP
oolSize
);
break
;
break
;
case
"druid"
:
case
"druid"
:
dataSource
=
DruidPoolBuilder
.
getDataSource
(
host
,
p
oolSize
);
dataSource
=
DruidPoolBuilder
.
getDataSource
(
host
,
connectionP
oolSize
);
break
;
break
;
case
"hikari"
:
case
"hikari"
:
default
:
default
:
dataSource
=
HikariCpBuilder
.
getDataSource
(
host
,
p
oolSize
);
dataSource
=
HikariCpBuilder
.
getDataSource
(
host
,
connectionP
oolSize
);
poolType
=
"hikari"
;
poolType
=
"hikari"
;
}
}
logger
.
info
(
">>>>>>>>>>>>>> connection pool Type: "
+
poolType
);
logger
.
info
(
">>>>>>>>>>>>>> connection pool Type: "
+
poolType
);
init
(
dataSource
);
init
(
dataSource
);
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadCount
);
ThreadPoolExecutor
executor
=
(
ThreadPoolExecutor
)
Executors
.
newFixedThreadPool
(
threadPoolSize
);
while
(
true
)
{
while
(
true
)
{
executor
.
execute
(
new
InsertTask
(
dataSource
,
dbName
,
tableSize
,
batchSize
));
executor
.
execute
(
new
InsertTask
(
dataSource
,
dbName
,
tableSize
,
batchSize
));
logger
.
info
(
"thread pool size : "
+
executor
.
getPoolSize
()
+
", active pool size: "
+
executor
.
getActiveCount
());
if
(
sleep
>
0
)
if
(
sleep
>
0
)
TimeUnit
.
MILLISECONDS
.
sleep
(
sleep
);
TimeUnit
.
MILLISECONDS
.
sleep
(
sleep
);
}
}
}
}
private
static
void
init
(
DataSource
dataSource
)
{
private
static
void
init
(
DataSource
dataSource
)
{
try
(
Connection
conn
=
dataSource
.
getConnection
())
{
try
(
Connection
conn
=
dataSource
.
getConnection
())
{
execute
(
conn
,
"drop database if exists "
+
dbName
+
""
);
execute
(
conn
,
"drop database if exists "
+
dbName
+
""
);
execute
(
conn
,
"create database if not exists "
+
dbName
+
""
);
execute
(
conn
,
"create database if not exists "
+
dbName
+
""
);
...
...
tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/pool/HikariCpBuilder.java
浏览文件 @
7e75e5ca
...
@@ -16,6 +16,13 @@ public class HikariCpBuilder {
...
@@ -16,6 +16,13 @@ public class HikariCpBuilder {
config
.
setMaximumPoolSize
(
poolSize
);
config
.
setMaximumPoolSize
(
poolSize
);
config
.
setMinimumIdle
(
poolSize
);
config
.
setMinimumIdle
(
poolSize
);
config
.
setMinimumIdle
(
3
);
config
.
setMaximumPoolSize
(
500
);
config
.
setMaxLifetime
(
2000000
);
config
.
setConnectionTimeout
(
30000
);
config
.
setIdleTimeout
(
30000
);
HikariDataSource
ds
=
new
HikariDataSource
(
config
);
HikariDataSource
ds
=
new
HikariDataSource
(
config
);
return
ds
;
return
ds
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录