Polishing

(cherry picked from commit 749b65b)
This commit is contained in:
Juergen Hoeller
2014-02-07 17:42:37 +01:00
parent 7e9cb5195a
commit 3da9a3193c
5 changed files with 49 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* 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.
@@ -27,14 +27,17 @@ import org.springframework.beans.factory.config.Scope;
import org.springframework.core.NamedThreadLocal;
/**
* Thread-backed {@link Scope} implementation.
* A simple thread-backed {@link Scope} implementation.
*
* <p><strong>Note</strong> that the {@code SimpleThreadScope} <em>does not clean up any objects</em> associated
* with it. As such, it's typically preferable to use the {@link org.springframework.web.context.request.RequestScope}
* in Web environments.
* <p><strong>Note:</strong> {@code SimpleThreadScope} <em>does not clean up
* any objects</em> associated with it. As such, it is typically preferable to
* use {@link org.springframework.web.context.request.RequestScope RequestScope}
* in web environments.
*
* <p>For a implementation of a thread-based {@code Scope} with support for destruction callbacks, refer to <a
* href="http://www.springbyexample.org/twiki/bin/view/Example/CustomThreadScopeModule">this module</a>.
* <p>For an implementation of a thread-based {@code Scope} with support for
* destruction callbacks, refer to the
* <a href="http://www.springbyexample.org/examples/custom-thread-scope-module.html">
* Spring by Example Custom Thread Scope Module</a>.
*
* <p>Thanks to Eugene Kuleshov for submitting the original prototype for a thread scope!
*
@@ -55,8 +58,9 @@ public class SimpleThreadScope implements Scope {
}
};
public Object get(String name, ObjectFactory objectFactory) {
Map<String, Object> scope = threadScope.get();
public Object get(String name, ObjectFactory<?> objectFactory) {
Map<String, Object> scope = this.threadScope.get();
Object object = scope.get(name);
if (object == null) {
object = objectFactory.getObject();
@@ -66,13 +70,13 @@ public class SimpleThreadScope implements Scope {
}
public Object remove(String name) {
Map<String, Object> scope = threadScope.get();
Map<String, Object> scope = this.threadScope.get();
return scope.remove(name);
}
public void registerDestructionCallback(String name, Runnable callback) {
logger.warn("SimpleThreadScope does not support descruction callbacks. " +
"Consider using a RequestScope in a Web environment.");
logger.warn("SimpleThreadScope does not support destruction callbacks. " +
"Consider using RequestScope in a web environment.");
}
public Object resolveContextualObject(String key) {