Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
521bbfcf
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
521bbfcf
编写于
9月 29, 2014
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow configuring custom ThreadPoolTaskExecutor
Issue: SPR-12272
上级
179b2366
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
35 deletion
+29
-35
spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java
...gframework/messaging/simp/config/ChannelRegistration.java
+12
-0
spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java
...ework/messaging/simp/config/TaskExecutorRegistration.java
+10
-1
spring-messaging/src/main/java/org/springframework/messaging/support/Test.java
...main/java/org/springframework/messaging/support/Test.java
+0
-31
spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java
...essaging/simp/config/MessageBrokerConfigurationTests.java
+7
-3
未找到文件。
spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java
浏览文件 @
521bbfcf
...
...
@@ -21,6 +21,7 @@ import java.util.Arrays;
import
java.util.List
;
import
org.springframework.messaging.support.ChannelInterceptor
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
/**
* A registration class for customizing the configuration for a
...
...
@@ -46,6 +47,17 @@ public class ChannelRegistration {
return
this
.
registration
;
}
/**
* Configure the thread pool backing this message channel using a custom
* ThreadPoolTaskExecutor.
*/
public
TaskExecutorRegistration
taskExecutor
(
ThreadPoolTaskExecutor
taskExecutor
)
{
if
(
this
.
registration
==
null
)
{
this
.
registration
=
new
TaskExecutorRegistration
(
taskExecutor
);
}
return
this
.
registration
;
}
/**
* Configure interceptors for the message channel.
*/
...
...
spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java
浏览文件 @
521bbfcf
...
...
@@ -26,6 +26,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
*/
public
class
TaskExecutorRegistration
{
private
ThreadPoolTaskExecutor
taskExecutor
;
private
int
corePoolSize
=
Runtime
.
getRuntime
().
availableProcessors
()
*
2
;
private
int
maxPoolSize
=
Integer
.
MAX_VALUE
;
...
...
@@ -35,6 +37,13 @@ public class TaskExecutorRegistration {
private
int
keepAliveSeconds
=
60
;
public
TaskExecutorRegistration
()
{
}
public
TaskExecutorRegistration
(
ThreadPoolTaskExecutor
taskExecutor
)
{
this
.
taskExecutor
=
taskExecutor
;
}
/**
* Set the core pool size of the ThreadPoolExecutor.
* <p><strong>NOTE:</strong> The core pool size is effectively the max pool size
...
...
@@ -93,7 +102,7 @@ public class TaskExecutorRegistration {
}
protected
ThreadPoolTaskExecutor
getTaskExecutor
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
(
);
ThreadPoolTaskExecutor
executor
=
(
this
.
taskExecutor
!=
null
?
this
.
taskExecutor
:
new
ThreadPoolTaskExecutor
()
);
executor
.
setCorePoolSize
(
this
.
corePoolSize
);
executor
.
setMaxPoolSize
(
this
.
maxPoolSize
);
executor
.
setKeepAliveSeconds
(
this
.
keepAliveSeconds
);
...
...
spring-messaging/src/main/java/org/springframework/messaging/support/Test.java
已删除
100644 → 0
浏览文件 @
179b2366
/*
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.messaging.support
;
/**
* @author Rossen Stoyanchev
* @since 4.1
*/
public
class
Test
{
public
static
void
main
(
String
[]
args
)
{
ExecutorSubscribableChannel
.
ExecutorSubscribableChannelTask
task
=
null
;
}
}
spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java
浏览文件 @
521bbfcf
...
...
@@ -132,8 +132,8 @@ public class MessageBrokerConfigurationTests {
assertEquals
(
2
,
channel
.
getInterceptors
().
size
());
ThreadPoolTaskExecutor
taskExecutor
=
this
.
customContext
.
getBean
(
"clientInboundChannelExecutor"
,
ThreadPoolTaskExecutor
.
class
);
Custom
ThreadPoolTaskExecutor
taskExecutor
=
this
.
customContext
.
getBean
(
"clientInboundChannelExecutor"
,
Custom
ThreadPoolTaskExecutor
.
class
);
assertEquals
(
11
,
taskExecutor
.
getCorePoolSize
());
assertEquals
(
12
,
taskExecutor
.
getMaxPoolSize
());
...
...
@@ -489,7 +489,8 @@ public class MessageBrokerConfigurationTests {
@Override
protected
void
configureClientInboundChannel
(
ChannelRegistration
registration
)
{
registration
.
setInterceptors
(
this
.
interceptor
);
registration
.
taskExecutor
().
corePoolSize
(
11
).
maxPoolSize
(
12
).
keepAliveSeconds
(
13
).
queueCapacity
(
14
);
registration
.
taskExecutor
(
new
CustomThreadPoolTaskExecutor
())
.
corePoolSize
(
11
).
maxPoolSize
(
12
).
keepAliveSeconds
(
13
).
queueCapacity
(
14
);
}
@Override
...
...
@@ -540,4 +541,7 @@ public class MessageBrokerConfigurationTests {
}
}
private
static
class
CustomThreadPoolTaskExecutor
extends
ThreadPoolTaskExecutor
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录