Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
f1772539
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
267
Star
16139
Fork
68
代码
文件
提交
分支
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看板
提交
f1772539
编写于
12月 06, 2018
作者:
M
maowei.ymw
提交者:
von gosling
12月 10, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify the asynchronous send thread pool to a exclusive one
上级
3482f944
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
5 deletion
+41
-5
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
.../rocketmq/client/impl/producer/DefaultMQProducerImpl.java
+31
-5
client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java
...rg/apache/rocketmq/client/producer/DefaultMQProducer.java
+10
-0
未找到文件。
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
浏览文件 @
f1772539
...
...
@@ -30,8 +30,10 @@ import java.util.concurrent.ConcurrentMap;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.RejectedExecutionException
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.apache.rocketmq.client.QueryResult
;
import
org.apache.rocketmq.client.Validators
;
import
org.apache.rocketmq.client.common.ClientErrorCode
;
...
...
@@ -101,6 +103,10 @@ public class DefaultMQProducerImpl implements MQProducerInner {
private
MQFaultStrategy
mqFaultStrategy
=
new
MQFaultStrategy
();
private
final
BlockingQueue
<
Runnable
>
asyncSenderThreadPoolQueue
;
private
final
ExecutorService
defaultAsyncSenderExecutor
;
private
ExecutorService
asyncSenderExecutor
;
public
DefaultMQProducerImpl
(
final
DefaultMQProducer
defaultMQProducer
)
{
this
(
defaultMQProducer
,
null
);
}
...
...
@@ -108,6 +114,22 @@ public class DefaultMQProducerImpl implements MQProducerInner {
public
DefaultMQProducerImpl
(
final
DefaultMQProducer
defaultMQProducer
,
RPCHook
rpcHook
)
{
this
.
defaultMQProducer
=
defaultMQProducer
;
this
.
rpcHook
=
rpcHook
;
this
.
asyncSenderThreadPoolQueue
=
new
LinkedBlockingQueue
<
Runnable
>(
50000
);
this
.
defaultAsyncSenderExecutor
=
new
ThreadPoolExecutor
(
Runtime
.
getRuntime
().
availableProcessors
(),
Runtime
.
getRuntime
().
availableProcessors
(),
1000
*
60
,
TimeUnit
.
MILLISECONDS
,
this
.
asyncSenderThreadPoolQueue
,
new
ThreadFactory
()
{
private
AtomicInteger
threadIndex
=
new
AtomicInteger
(
0
);
@Override
public
Thread
newThread
(
Runnable
r
)
{
return
new
Thread
(
r
,
"AsyncSenderExecutor_"
+
this
.
threadIndex
.
incrementAndGet
());
}
});
}
public
void
registerCheckForbiddenHook
(
CheckForbiddenHook
checkForbiddenHook
)
{
...
...
@@ -456,7 +478,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
public
void
send
(
final
Message
msg
,
final
SendCallback
sendCallback
,
final
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
final
long
beginStartTime
=
System
.
currentTimeMillis
();
ExecutorService
executor
=
this
.
get
Callback
Executor
();
ExecutorService
executor
=
this
.
get
AsyncSender
Executor
();
try
{
executor
.
submit
(
new
Runnable
()
{
@Override
...
...
@@ -957,7 +979,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
public
void
send
(
final
Message
msg
,
final
MessageQueue
mq
,
final
SendCallback
sendCallback
,
final
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
final
long
beginStartTime
=
System
.
currentTimeMillis
();
ExecutorService
executor
=
this
.
get
Callback
Executor
();
ExecutorService
executor
=
this
.
get
AsyncSender
Executor
();
try
{
executor
.
submit
(
new
Runnable
()
{
@Override
...
...
@@ -1079,7 +1101,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
public
void
send
(
final
Message
msg
,
final
MessageQueueSelector
selector
,
final
Object
arg
,
final
SendCallback
sendCallback
,
final
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
final
long
beginStartTime
=
System
.
currentTimeMillis
();
ExecutorService
executor
=
this
.
get
Callback
Executor
();
ExecutorService
executor
=
this
.
get
AsyncSender
Executor
();
try
{
executor
.
submit
(
new
Runnable
()
{
@Override
...
...
@@ -1243,9 +1265,13 @@ public class DefaultMQProducerImpl implements MQProducerInner {
public
void
setCallbackExecutor
(
final
ExecutorService
callbackExecutor
)
{
this
.
mQClientFactory
.
getMQClientAPIImpl
().
getRemotingClient
().
setCallbackExecutor
(
callbackExecutor
);
}
public
ExecutorService
getCallbackExecutor
()
{
return
this
.
mQClientFactory
.
getMQClientAPIImpl
().
getRemotingClient
().
getCallbackExecutor
();
public
ExecutorService
getAsyncSenderExecutor
()
{
return
null
==
asyncSenderExecutor
?
defaultAsyncSenderExecutor
:
asyncSenderExecutor
;
}
public
void
setAsyncSenderExecutor
(
ExecutorService
asyncSenderExecutor
)
{
this
.
asyncSenderExecutor
=
asyncSenderExecutor
;
}
public
SendResult
send
(
Message
msg
,
...
...
client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java
浏览文件 @
f1772539
...
...
@@ -655,6 +655,16 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
this
.
defaultMQProducerImpl
.
setCallbackExecutor
(
callbackExecutor
);
}
/**
* Sets an Executor to be used for executing asynchronous send. If the Executor is not set, {@link
* DefaultMQProducerImpl#defaultAsyncSenderExecutor} will be used.
*
* @param asyncSenderExecutor the instance of Executor
*/
public
void
setAsyncSenderExecutor
(
final
ExecutorService
asyncSenderExecutor
)
{
this
.
defaultMQProducerImpl
.
setAsyncSenderExecutor
(
asyncSenderExecutor
);
}
private
MessageBatch
batch
(
Collection
<
Message
>
msgs
)
throws
MQClientException
{
MessageBatch
msgBatch
;
try
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录