Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
8d8e218b
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 搜索 >>
提交
8d8e218b
编写于
3月 23, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent FactoryBean cache visibility in concurrent creation scenarios
Issue: SPR-16625 Issue: SPR-16627
上级
937cd48f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
24 deletion
+42
-24
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
...s/factory/support/AbstractAutowireCapableBeanFactory.java
+20
-3
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
...k/beans/factory/support/DefaultSingletonBeanRegistry.java
+12
-15
spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java
...ork/beans/factory/support/FactoryBeanRegistrySupport.java
+10
-6
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
浏览文件 @
8d8e218b
...
...
@@ -927,12 +927,16 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
if
(
bw
!=
null
)
{
return
(
FactoryBean
<?>)
bw
.
getWrappedInstance
();
}
Object
beanInstance
=
getSingleton
(
beanName
,
false
);
if
(
beanInstance
instanceof
FactoryBean
)
{
return
(
FactoryBean
<?>)
beanInstance
;
}
if
(
isSingletonCurrentlyInCreation
(
beanName
)
||
(
mbd
.
getFactoryBeanName
()
!=
null
&&
isSingletonCurrentlyInCreation
(
mbd
.
getFactoryBeanName
())))
{
return
null
;
}
Object
instance
=
null
;
Object
instance
;
try
{
// Mark this bean as currently in creation, even if just partially.
beforeSingletonCreation
(
beanName
);
...
...
@@ -1845,8 +1849,21 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
*/
@Override
protected
void
removeSingleton
(
String
beanName
)
{
super
.
removeSingleton
(
beanName
);
this
.
factoryBeanInstanceCache
.
remove
(
beanName
);
synchronized
(
getSingletonMutex
())
{
super
.
removeSingleton
(
beanName
);
this
.
factoryBeanInstanceCache
.
remove
(
beanName
);
}
}
/**
* Overridden to clear FactoryBean instance cache as well.
*/
@Override
protected
void
clearSingletonCache
()
{
synchronized
(
getSingletonMutex
())
{
super
.
clearSingletonCache
();
this
.
factoryBeanInstanceCache
.
clear
();
}
}
...
...
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
浏览文件 @
8d8e218b
...
...
@@ -392,11 +392,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
// No entry yet -> fully synchronized manipulation of the containedBeans Set
synchronized
(
this
.
containedBeanMap
)
{
containedBeans
=
this
.
containedBeanMap
.
get
(
containingBeanName
);
if
(
containedBeans
==
null
)
{
containedBeans
=
new
LinkedHashSet
<>(
8
);
this
.
containedBeanMap
.
put
(
containingBeanName
,
containedBeans
);
}
containedBeans
=
this
.
containedBeanMap
.
computeIfAbsent
(
containingBeanName
,
k
->
new
LinkedHashSet
<>(
8
));
containedBeans
.
add
(
containedBeanName
);
}
registerDependentBean
(
containedBeanName
,
containingBeanName
);
...
...
@@ -418,19 +414,12 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
// No entry yet -> fully synchronized manipulation of the dependentBeans Set
synchronized
(
this
.
dependentBeanMap
)
{
dependentBeans
=
this
.
dependentBeanMap
.
get
(
canonicalName
);
if
(
dependentBeans
==
null
)
{
dependentBeans
=
new
LinkedHashSet
<>(
8
);
this
.
dependentBeanMap
.
put
(
canonicalName
,
dependentBeans
);
}
dependentBeans
=
this
.
dependentBeanMap
.
computeIfAbsent
(
canonicalName
,
k
->
new
LinkedHashSet
<>(
8
));
dependentBeans
.
add
(
dependentBeanName
);
}
synchronized
(
this
.
dependenciesForBeanMap
)
{
Set
<
String
>
dependenciesForBean
=
this
.
dependenciesForBeanMap
.
get
(
dependentBeanName
);
if
(
dependenciesForBean
==
null
)
{
dependenciesForBean
=
new
LinkedHashSet
<>(
8
);
this
.
dependenciesForBeanMap
.
put
(
dependentBeanName
,
dependenciesForBean
);
}
Set
<
String
>
dependenciesForBean
=
this
.
dependenciesForBeanMap
.
computeIfAbsent
(
dependentBeanName
,
k
->
new
LinkedHashSet
<>(
8
));
dependenciesForBean
.
add
(
canonicalName
);
}
}
...
...
@@ -525,6 +514,14 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
this
.
dependentBeanMap
.
clear
();
this
.
dependenciesForBeanMap
.
clear
();
clearSingletonCache
();
}
/**
* Clear all cached singleton instances in this registry.
* @since 4.3.15
*/
protected
void
clearSingletonCache
()
{
synchronized
(
this
.
singletonObjects
)
{
this
.
singletonObjects
.
clear
();
this
.
singletonFactories
.
clear
();
...
...
spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java
浏览文件 @
8d8e218b
/*
* 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.
...
...
@@ -214,17 +214,21 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg
*/
@Override
protected
void
removeSingleton
(
String
beanName
)
{
super
.
removeSingleton
(
beanName
);
this
.
factoryBeanObjectCache
.
remove
(
beanName
);
synchronized
(
getSingletonMutex
())
{
super
.
removeSingleton
(
beanName
);
this
.
factoryBeanObjectCache
.
remove
(
beanName
);
}
}
/**
* Overridden to clear the FactoryBean object cache as well.
*/
@Override
public
void
destroySingletons
()
{
super
.
destroySingletons
();
this
.
factoryBeanObjectCache
.
clear
();
protected
void
clearSingletonCache
()
{
synchronized
(
getSingletonMutex
())
{
super
.
clearSingletonCache
();
this
.
factoryBeanObjectCache
.
clear
();
}
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录