Merge branch '5.2.x'

This commit is contained in:
Sam Brannen 2020-08-22 23:50:28 +02:00
commit 0f7ad1b5bf
4 changed files with 15 additions and 45 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -16,8 +16,8 @@
package org.springframework.context.support;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -59,7 +59,7 @@ public class SimpleThreadScope implements Scope {
new NamedThreadLocal<Map<String, Object>>("SimpleThreadScope") {
@Override
protected Map<String, Object> initialValue() {
return new HashMap<>();
return new ConcurrentHashMap<>();
}
};

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -30,14 +30,14 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Arjen Poutsma
* @author Sam Brannen
*/
public class SimpleThreadScopeTests {
class SimpleThreadScopeTests {
private final ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("simpleThreadScopeTests.xml", getClass());
@Test
public void getFromScope() throws Exception {
void getFromScope() throws Exception {
String name = "threadScopedObject";
TestBean bean = this.applicationContext.getBean(name, TestBean.class);
assertThat(bean).isNotNull();
@ -47,7 +47,7 @@ public class SimpleThreadScopeTests {
}
@Test
public void getMultipleInstances() throws Exception {
void getMultipleInstances() throws Exception {
// Arrange
TestBean[] beans = new TestBean[2];
Thread thread1 = new Thread(() -> beans[0] = applicationContext.getBean("threadScopedObject", TestBean.class));

View File

@ -1,51 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="thread">
<bean class="org.springframework.context.support.SimpleThreadScope"/>
<bean class="org.springframework.context.support.SimpleThreadScope" />
</entry>
</map>
</property>
</bean>
<bean id="threadScopedObject" class="org.springframework.beans.testfixture.beans.TestBean" scope="thread"/>
<!--
<bean id="requestScopedDisposableObject" class="org.springframework.beans.testfixture.beans.DerivedTestBean" scope="request"/>
<bean id="requestScopedFactoryBean" class="org.springframework.beans.testfixture.beans.factory.DummyFactory" scope="request"/>
<bean id="requestScopedObjectCircle1" class="org.springframework.beans.testfixture.beans.TestBean" scope="request">
<property name="spouse" ref="requestScopedObjectCircle2"/>
<bean id="threadScopedObject" class="org.springframework.beans.testfixture.beans.TestBean" scope="thread">
<property name="spouse" ref="threadScopedObject2" />
</bean>
<bean id="requestScopedObjectCircle2" class="org.springframework.beans.testfixture.beans.TestBean" scope="request">
<property name="spouse" ref="requestScopedObjectCircle1"/>
</bean>
<bean id="threadScopedObject2" class="org.springframework.beans.testfixture.beans.TestBean" scope="thread" />
<bean id="requestScopedOuterBean" class="org.springframework.beans.testfixture.beans.DerivedTestBean" scope="request">
<property name="name" value="outer"/>
<property name="spouse">
<bean class="org.springframework.beans.testfixture.beans.DerivedTestBean">
<property name="name" value="inner"/>
</bean>
</property>
</bean>
<bean id="singletonOuterBean" class="org.springframework.beans.testfixture.beans.DerivedTestBean" lazy-init="true">
<property name="name" value="outer"/>
<property name="spouse">
<bean class="org.springframework.beans.testfixture.beans.DerivedTestBean" scope="request">
<property name="name" value="inner"/>
</bean>
</property>
</bean>
-->
</beans>

View File

@ -16,9 +16,9 @@
package org.springframework.transaction.support;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;
@ -92,7 +92,7 @@ public class SimpleTransactionScope implements Scope {
*/
static class ScopedObjectsHolder {
final Map<String, Object> scopedInstances = new HashMap<>();
final Map<String, Object> scopedInstances = new ConcurrentHashMap<>();
final Map<String, Runnable> destructionCallbacks = new LinkedHashMap<>();
}