Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6cf19786
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 搜索 >>
提交
6cf19786
编写于
6月 06, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DefaultLifecycleProcessor properly handles count for dependent beans
Issue: SPR-16901
上级
0941081b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
22 deletion
+24
-22
spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSchedulerLifecycleTests.java
...work/scheduling/quartz/QuartzSchedulerLifecycleTests.java
+6
-4
spring-context-support/src/test/resources/org/springframework/scheduling/quartz/quartzSchedulerLifecycleTests.xml
...ework/scheduling/quartz/quartzSchedulerLifecycleTests.xml
+8
-2
spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java
...gframework/context/support/DefaultLifecycleProcessor.java
+10
-16
未找到文件。
spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSchedulerLifecycleTests.java
浏览文件 @
6cf19786
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -18,7 +18,7 @@ package org.springframework.scheduling.quartz;
import
org.junit.Test
;
import
org.springframework.context.
support.Abstract
ApplicationContext
;
import
org.springframework.context.
Configurable
ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.util.StopWatch
;
...
...
@@ -32,7 +32,8 @@ public class QuartzSchedulerLifecycleTests {
@Test
// SPR-6354
public
void
destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang
()
{
AbstractApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"quartzSchedulerLifecycleTests.xml"
,
this
.
getClass
());
ConfigurableApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"quartzSchedulerLifecycleTests.xml"
,
getClass
());
assertNotNull
(
context
.
getBean
(
"lazyInitSchedulerWithDefaultShutdownOrder"
));
StopWatch
sw
=
new
StopWatch
();
sw
.
start
(
"lazyScheduler"
);
...
...
@@ -44,7 +45,8 @@ public class QuartzSchedulerLifecycleTests {
@Test
// SPR-6354
public
void
destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang
()
{
AbstractApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"quartzSchedulerLifecycleTests.xml"
,
this
.
getClass
());
ConfigurableApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"quartzSchedulerLifecycleTests.xml"
,
getClass
());
assertNotNull
(
context
.
getBean
(
"lazyInitSchedulerWithCustomShutdownOrder"
));
StopWatch
sw
=
new
StopWatch
();
sw
.
start
(
"lazyScheduler"
);
...
...
spring-context-support/src/test/resources/org/springframework/scheduling/quartz/quartzSchedulerLifecycleTests.xml
浏览文件 @
6cf19786
...
...
@@ -4,9 +4,15 @@
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"
>
<bean
id=
"lazyInitSchedulerWithDefaultShutdownOrder"
class=
"org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init=
"true"
/>
<bean
id=
"otherSchedulerWithDefaultShutdownOrder"
class=
"org.springframework.scheduling.quartz.SchedulerFactoryBean"
>
<property
name=
"autoStartup"
value=
"false"
/>
</bean>
<bean
id=
"lazyInitSchedulerWithDefaultShutdownOrder"
class=
"org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init=
"true"
depends-on=
"otherSchedulerWithDefaultShutdownOrder"
/>
<bean
id=
"lazyInitSchedulerWithCustomShutdownOrder"
class=
"org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init=
"true"
>
<bean
id=
"lazyInitSchedulerWithCustomShutdownOrder"
class=
"org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init=
"true"
>
<property
name=
"phase"
value=
"99"
/>
</bean>
...
...
spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java
浏览文件 @
6cf19786
...
...
@@ -252,7 +252,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
}
}
else
if
(
bean
instanceof
SmartLifecycle
)
{
//
don't wait for beans that aren't running
//
Don't wait for beans that aren't running...
latch
.
countDown
();
}
}
...
...
@@ -317,8 +317,6 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
*/
private
class
LifecycleGroup
{
private
final
List
<
LifecycleGroupMember
>
members
=
new
ArrayList
<>();
private
final
int
phase
;
private
final
long
timeout
;
...
...
@@ -327,9 +325,13 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
private
final
boolean
autoStartupOnly
;
private
volatile
int
smartMemberCount
;
private
final
List
<
LifecycleGroupMember
>
members
=
new
ArrayList
<>();
private
int
smartMemberCount
;
public
LifecycleGroup
(
int
phase
,
long
timeout
,
Map
<
String
,
?
extends
Lifecycle
>
lifecycleBeans
,
boolean
autoStartupOnly
)
{
public
LifecycleGroup
(
int
phase
,
long
timeout
,
Map
<
String
,
?
extends
Lifecycle
>
lifecycleBeans
,
boolean
autoStartupOnly
)
{
this
.
phase
=
phase
;
this
.
timeout
=
timeout
;
this
.
lifecycleBeans
=
lifecycleBeans
;
...
...
@@ -337,10 +339,10 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
}
public
void
add
(
String
name
,
Lifecycle
bean
)
{
this
.
members
.
add
(
new
LifecycleGroupMember
(
name
,
bean
));
if
(
bean
instanceof
SmartLifecycle
)
{
this
.
smartMemberCount
++;
}
this
.
members
.
add
(
new
LifecycleGroupMember
(
name
,
bean
));
}
public
void
start
()
{
...
...
@@ -352,9 +354,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
}
Collections
.
sort
(
this
.
members
);
for
(
LifecycleGroupMember
member
:
this
.
members
)
{
if
(
this
.
lifecycleBeans
.
containsKey
(
member
.
name
))
{
doStart
(
this
.
lifecycleBeans
,
member
.
name
,
this
.
autoStartupOnly
);
}
doStart
(
this
.
lifecycleBeans
,
member
.
name
,
this
.
autoStartupOnly
);
}
}
...
...
@@ -369,13 +369,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
CountDownLatch
latch
=
new
CountDownLatch
(
this
.
smartMemberCount
);
Set
<
String
>
countDownBeanNames
=
Collections
.
synchronizedSet
(
new
LinkedHashSet
<>());
for
(
LifecycleGroupMember
member
:
this
.
members
)
{
if
(
this
.
lifecycleBeans
.
containsKey
(
member
.
name
))
{
doStop
(
this
.
lifecycleBeans
,
member
.
name
,
latch
,
countDownBeanNames
);
}
else
if
(
member
.
bean
instanceof
SmartLifecycle
)
{
// already removed, must have been a dependent
latch
.
countDown
();
}
doStop
(
this
.
lifecycleBeans
,
member
.
name
,
latch
,
countDownBeanNames
);
}
try
{
latch
.
await
(
this
.
timeout
,
TimeUnit
.
MILLISECONDS
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录