Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8980b090
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看板
提交
8980b090
编写于
6月 27, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: refactor highvolume example
上级
074fab00
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
18 addition
and
34 deletion
+18
-34
docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java
...in/java/com/taos/example/highvolume/FastWriteExample.java
+13
-13
docs/examples/java/src/main/java/com/taos/example/highvolume/WriteTask.java
.../src/main/java/com/taos/example/highvolume/WriteTask.java
+5
-21
未找到文件。
docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java
浏览文件 @
8980b090
...
@@ -2,30 +2,30 @@ package com.taos.example.highvolume;
...
@@ -2,30 +2,30 @@ package com.taos.example.highvolume;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingDeque
;
// ANCHOR: main
// ANCHOR: main
public
class
FastWriteExample
{
public
class
FastWriteExample
{
final
static
int
readTaskCount
=
1
;
final
static
int
readTaskCount
=
2
;
final
static
int
writeTaskCount
=
4
;
final
static
int
writeTaskCount
=
4
;
final
static
List
<
ReadTask
>
readTasks
=
new
ArrayList
<>()
;
final
static
int
taskQueueCapacity
=
1000
;
final
static
List
<
WriteTask
>
writeTask
s
=
new
ArrayList
<>();
final
static
List
<
BlockingQueue
>
taskQueue
s
=
new
ArrayList
<>();
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
// Create writing tasks.
// Create task queues, whiting tasks and start writing threads.
// Every writing task contains a work thread and a task queue.
for
(
int
i
=
0
;
i
<
writeTaskCount
;
++
i
)
{
for
(
int
i
=
0
;
i
<
writeTaskCount
;
++
i
)
{
WriteTask
task
=
new
WriteTask
();
BlockingQueue
<
String
>
queue
=
new
LinkedBlockingDeque
<>(
taskQueueCapacity
);
task
.
start
();
WriteTask
task
=
new
WriteTask
(
queue
);
writeTasks
.
add
(
new
WriteTask
());
Thread
t
=
new
Thread
(
task
);
t
.
start
();
}
}
// Create reading tasks.
// create reading tasks and start reading threads
// Every reading task contains a work thread and a reference to each writing task.
for
(
int
i
=
0
;
i
<
readTaskCount
;
++
i
)
{
for
(
int
i
=
0
;
i
<
readTaskCount
;
++
i
)
{
ReadTask
task
=
new
ReadTask
(
i
,
writeTasks
);
ReadTask
task
=
new
ReadTask
(
taskQueues
);
task
.
start
();
Thread
t
=
new
Thread
(
task
);
readTasks
.
add
(
task
);
}
}
while
(
true
)
{
while
(
true
)
{
...
...
docs/examples/java/src/main/java/com/taos/example/highvolume/WriteTask.java
浏览文件 @
8980b090
...
@@ -10,28 +10,12 @@ import java.util.concurrent.BlockingQueue;
...
@@ -10,28 +10,12 @@ import java.util.concurrent.BlockingQueue;
import
java.util.concurrent.LinkedBlockingDeque
;
import
java.util.concurrent.LinkedBlockingDeque
;
// ANCHOR: WriteTask
// ANCHOR: WriteTask
class
WriteTask
{
class
WriteTask
implements
Runnable
{
final
static
int
maxBatchSize
=
500
;
final
static
int
maxBatchSize
=
500
;
//
private
final
BlockingQueue
<
String
>
queue
;
final
static
int
taskQueueCapacity
=
1000
;
private
Thread
writeThread
=
new
Thread
(
this
::
doWriteTask
);
public
WriteTask
(
BlockingQueue
<
String
>
taskQueue
)
{
this
.
queue
=
taskQueue
;
private
BlockingQueue
<
String
>
queue
=
new
LinkedBlockingDeque
<>(
taskQueueCapacity
);
/**
* Public interface for adding task to task queue.
* It will be invoked in read thread.
*/
public
void
put
(
String
line
)
throws
InterruptedException
{
queue
.
put
(
line
);
}
/**
* Start writing thread.
*/
public
void
start
()
{
writeThread
.
start
();
}
}
private
static
Connection
getConnection
()
throws
SQLException
{
private
static
Connection
getConnection
()
throws
SQLException
{
...
@@ -39,7 +23,7 @@ class WriteTask {
...
@@ -39,7 +23,7 @@ class WriteTask {
return
DriverManager
.
getConnection
(
jdbcUrl
);
return
DriverManager
.
getConnection
(
jdbcUrl
);
}
}
p
rivate
void
doWriteTask
()
{
p
ublic
void
run
()
{
int
count
=
0
;
int
count
=
0
;
try
{
try
{
Connection
conn
=
getConnection
();
Connection
conn
=
getConnection
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录