Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
带水的鱼儿
spring-framework
提交
62e91653
S
spring-framework
项目概览
带水的鱼儿
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
62e91653
编写于
7月 13, 2021
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce remaining policy setters from ScheduledThreadPoolExecutor
Closes gh-26719
上级
e1c0f3b0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
23 deletion
+64
-23
spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
...mework/scheduling/concurrent/ThreadPoolTaskScheduler.java
+64
-23
未找到文件。
spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
浏览文件 @
62e91653
...
...
@@ -53,6 +53,8 @@ import org.springframework.util.concurrent.ListenableFutureTask;
* @since 3.0
* @see #setPoolSize
* @see #setRemoveOnCancelPolicy
* @see #setContinueExistingPeriodicTasksAfterShutdownPolicy
* @see #setExecuteExistingDelayedTasksAfterShutdownPolicy
* @see #setThreadFactory
* @see #setErrorHandler
*/
...
...
@@ -64,6 +66,10 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
private
volatile
boolean
removeOnCancelPolicy
;
private
volatile
boolean
continueExistingPeriodicTasksAfterShutdownPolicy
;
private
volatile
boolean
executeExistingDelayedTasksAfterShutdownPolicy
=
true
;
@Nullable
private
volatile
ErrorHandler
errorHandler
;
...
...
@@ -93,17 +99,45 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
/**
* Set the remove-on-cancel mode on {@link ScheduledThreadPoolExecutor}.
* <p>Default is {@code false}. If set to {@code true}, the target executor will be
* switched into remove-on-cancel mode (if possible
, with a soft fallback otherwise
).
* switched into remove-on-cancel mode (if possible).
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
* @see ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy
*/
public
void
setRemoveOnCancelPolicy
(
boolean
removeOnCancelPolicy
)
{
public
void
setRemoveOnCancelPolicy
(
boolean
flag
)
{
if
(
this
.
scheduledExecutor
instanceof
ScheduledThreadPoolExecutor
)
{
((
ScheduledThreadPoolExecutor
)
this
.
scheduledExecutor
).
setRemoveOnCancelPolicy
(
removeOnCancelPolicy
);
((
ScheduledThreadPoolExecutor
)
this
.
scheduledExecutor
).
setRemoveOnCancelPolicy
(
flag
);
}
else
if
(
removeOnCancelPolicy
&&
this
.
scheduledExecutor
!=
null
)
{
logger
.
debug
(
"Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor"
);
this
.
removeOnCancelPolicy
=
flag
;
}
/**
* Set whether to continue existing periodic tasks even when this executor has been shutdown.
* <p>Default is {@code false}. If set to {@code true}, the target executor will be
* switched into continuing periodic tasks (if possible).
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
* @since 5.3.9
* @see ScheduledThreadPoolExecutor#setContinueExistingPeriodicTasksAfterShutdownPolicy
*/
public
void
setContinueExistingPeriodicTasksAfterShutdownPolicy
(
boolean
flag
)
{
if
(
this
.
scheduledExecutor
instanceof
ScheduledThreadPoolExecutor
)
{
((
ScheduledThreadPoolExecutor
)
this
.
scheduledExecutor
).
setContinueExistingPeriodicTasksAfterShutdownPolicy
(
flag
);
}
this
.
removeOnCancelPolicy
=
removeOnCancelPolicy
;
this
.
continueExistingPeriodicTasksAfterShutdownPolicy
=
flag
;
}
/**
* Set whether to execute existing delayed tasks even when this executor has been shutdown.
* <p>Default is {@code true}. If set to {@code false}, the target executor will be
* switched into dropping remaining tasks (if possible).
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
* @since 5.3.9
* @see ScheduledThreadPoolExecutor#setExecuteExistingDelayedTasksAfterShutdownPolicy
*/
public
void
setExecuteExistingDelayedTasksAfterShutdownPolicy
(
boolean
flag
)
{
if
(
this
.
scheduledExecutor
instanceof
ScheduledThreadPoolExecutor
)
{
((
ScheduledThreadPoolExecutor
)
this
.
scheduledExecutor
).
setExecuteExistingDelayedTasksAfterShutdownPolicy
(
flag
);
}
this
.
executeExistingDelayedTasksAfterShutdownPolicy
=
flag
;
}
/**
...
...
@@ -135,12 +169,16 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
this
.
scheduledExecutor
=
createExecutor
(
this
.
poolSize
,
threadFactory
,
rejectedExecutionHandler
);
if
(
this
.
removeOnCancelPolicy
)
{
if
(
this
.
scheduledExecutor
instanceof
ScheduledThreadPoolExecutor
)
{
((
ScheduledThreadPoolExecutor
)
this
.
scheduledExecutor
).
setRemoveOnCancelPolicy
(
true
);
if
(
this
.
scheduledExecutor
instanceof
ScheduledThreadPoolExecutor
)
{
ScheduledThreadPoolExecutor
scheduledPoolExecutor
=
(
ScheduledThreadPoolExecutor
)
this
.
scheduledExecutor
;
if
(
this
.
removeOnCancelPolicy
)
{
scheduledPoolExecutor
.
setRemoveOnCancelPolicy
(
true
);
}
if
(
this
.
continueExistingPeriodicTasksAfterShutdownPolicy
)
{
scheduledPoolExecutor
.
setContinueExistingPeriodicTasksAfterShutdownPolicy
(
true
);
}
else
{
logger
.
debug
(
"Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor"
);
if
(!
this
.
executeExistingDelayedTasksAfterShutdownPolicy
)
{
scheduledPoolExecutor
.
setExecuteExistingDelayedTasksAfterShutdownPolicy
(
false
);
}
}
...
...
@@ -201,18 +239,6 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
return
getScheduledThreadPoolExecutor
().
getPoolSize
();
}
/**
* Return the current setting for the remove-on-cancel mode.
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
*/
public
boolean
isRemoveOnCancelPolicy
()
{
if
(
this
.
scheduledExecutor
==
null
)
{
// Not initialized yet: return our setting for the time being.
return
this
.
removeOnCancelPolicy
;
}
return
getScheduledThreadPoolExecutor
().
getRemoveOnCancelPolicy
();
}
/**
* Return the number of currently active threads.
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
...
...
@@ -227,6 +253,21 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
return
getScheduledThreadPoolExecutor
().
getActiveCount
();
}
/**
* Return the current setting for the remove-on-cancel mode.
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
* @deprecated as of 5.3.9, in favor of direct
* {@link #getScheduledThreadPoolExecutor()} access
*/
@Deprecated
public
boolean
isRemoveOnCancelPolicy
()
{
if
(
this
.
scheduledExecutor
==
null
)
{
// Not initialized yet: return our setting for the time being.
return
this
.
removeOnCancelPolicy
;
}
return
getScheduledThreadPoolExecutor
().
getRemoveOnCancelPolicy
();
}
// SchedulingTaskExecutor implementation
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录