Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
94abced3
R
Rocketmq
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
94abced3
编写于
7月 31, 2021
作者:
P
panzhi
提交者:
GitHub
7月 31, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ISSUE #3199] Two timed task for RequestFutureTable (#3202)
Co-authored-by:
N
panzhi33
<
wb-pz502261@alibaba-inc.com
>
上级
3e014241
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
13 deletion
+34
-13
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
.../rocketmq/client/impl/producer/DefaultMQProducerImpl.java
+27
-13
client/src/main/java/org/apache/rocketmq/client/producer/RequestFutureTable.java
...g/apache/rocketmq/client/producer/RequestFutureTable.java
+7
-0
未找到文件。
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
浏览文件 @
94abced3
...
...
@@ -24,14 +24,14 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.Random
;
import
java.util.Set
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.RejectedExecutionException
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -107,7 +107,12 @@ public class DefaultMQProducerImpl implements MQProducerInner {
private
final
RPCHook
rpcHook
;
private
final
BlockingQueue
<
Runnable
>
asyncSenderThreadPoolQueue
;
private
final
ExecutorService
defaultAsyncSenderExecutor
;
private
final
Timer
timer
=
new
Timer
(
"RequestHouseKeepingService"
,
true
);
private
final
ScheduledExecutorService
scheduledExecutorService
=
Executors
.
newSingleThreadScheduledExecutor
(
new
ThreadFactory
()
{
@Override
public
Thread
newThread
(
Runnable
r
)
{
return
new
Thread
(
r
,
"RequestHouseKeepingService"
);
}
});
protected
BlockingQueue
<
Runnable
>
checkRequestQueue
;
protected
ExecutorService
checkExecutor
;
private
ServiceState
serviceState
=
ServiceState
.
CREATE_JUST
;
...
...
@@ -227,16 +232,23 @@ public class DefaultMQProducerImpl implements MQProducerInner {
this
.
mQClientFactory
.
sendHeartbeatToAllBrokerWithLock
();
this
.
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
try
{
RequestFutureTable
.
scanExpiredRequest
();
}
catch
(
Throwable
e
)
{
log
.
error
(
"scan RequestFutureTable exception"
,
e
);
this
.
startScheduledTask
();
}
private
void
startScheduledTask
()
{
if
(
RequestFutureTable
.
getProducerNum
().
incrementAndGet
()
==
1
)
{
this
.
scheduledExecutorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
RequestFutureTable
.
scanExpiredRequest
();
}
catch
(
Throwable
e
)
{
log
.
error
(
"scan RequestFutureTable exception"
,
e
);
}
}
}
}
,
1000
*
3
,
1000
);
}
,
1000
*
3
,
1000
,
TimeUnit
.
MILLISECONDS
);
}
}
private
void
checkConfig
()
throws
MQClientException
{
...
...
@@ -266,7 +278,9 @@ public class DefaultMQProducerImpl implements MQProducerInner {
if
(
shutdownFactory
)
{
this
.
mQClientFactory
.
shutdown
();
}
this
.
timer
.
cancel
();
if
(
RequestFutureTable
.
getProducerNum
().
decrementAndGet
()
==
0
)
{
scheduledExecutorService
.
shutdown
();
}
log
.
info
(
"the producer [{}] shutdown OK"
,
this
.
defaultMQProducer
.
getProducerGroup
());
this
.
serviceState
=
ServiceState
.
SHUTDOWN_ALREADY
;
break
;
...
...
client/src/main/java/org/apache/rocketmq/client/producer/RequestFutureTable.java
浏览文件 @
94abced3
...
...
@@ -22,6 +22,8 @@ import java.util.LinkedList;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.apache.rocketmq.client.common.ClientErrorCode
;
import
org.apache.rocketmq.client.exception.RequestTimeoutException
;
import
org.apache.rocketmq.client.log.ClientLogger
;
...
...
@@ -30,6 +32,7 @@ import org.apache.rocketmq.logging.InternalLogger;
public
class
RequestFutureTable
{
private
static
InternalLogger
log
=
ClientLogger
.
getLog
();
private
static
ConcurrentHashMap
<
String
,
RequestResponseFuture
>
requestFutureTable
=
new
ConcurrentHashMap
<
String
,
RequestResponseFuture
>();
private
static
final
AtomicInteger
producerNum
=
new
AtomicInteger
(
0
);
public
static
ConcurrentHashMap
<
String
,
RequestResponseFuture
>
getRequestFutureTable
()
{
return
requestFutureTable
;
...
...
@@ -59,4 +62,8 @@ public class RequestFutureTable {
}
}
}
public
static
AtomicInteger
getProducerNum
()
{
return
producerNum
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录