Spring Framework

Provide out of the box implementation of the thread scope

Details

  • Type: New Feature New Feature
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0 final
  • Fix Version/s: 3.0 M2
  • Component/s: SpringCORE
  • Description:
    Hide

    Thread-bound scope can help to address concurrency issues (e.g. batching up requests per thread). So, it would be really handy if Spring provided such scope out of the box for Spring 2.0. E.g. something like this:

    public class ThreadScope implements Scope {
    
      private final ThreadLocal threadScope = new ThreadLocal() {
          protected Object initialValue() {
            return new HashMap();
          }
        };
      
      public Object get(String name, ObjectFactory objectFactory) {
        Map scope = (Map) threadScope.get();
        Object object = scope.get(name);
        if(object==null) {
          object = objectFactory.getObject();
          scope.put(name, object);
        }
        return object;
      }
    
      public Object remove(String name) {
        Map scope = (Map) threadScope.get();
        return scope.remove(name);
      }
    
      public void registerDestructionCallback(String name, Runnable callback) {
      }
      
    }
    Show
    Thread-bound scope can help to address concurrency issues (e.g. batching up requests per thread). So, it would be really handy if Spring provided such scope out of the box for Spring 2.0. E.g. something like this:
    public class ThreadScope implements Scope {
    
      private final ThreadLocal threadScope = new ThreadLocal() {
          protected Object initialValue() {
            return new HashMap();
          }
        };
      
      public Object get(String name, ObjectFactory objectFactory) {
        Map scope = (Map) threadScope.get();
        Object object = scope.get(name);
        if(object==null) {
          object = objectFactory.getObject();
          scope.put(name, object);
        }
        return object;
      }
    
      public Object remove(String name) {
        Map scope = (Map) threadScope.get();
        return scope.remove(name);
      }
    
      public void registerDestructionCallback(String name, Runnable callback) {
      }
      
    }

Activity

Juergen Hoeller made changes - 25/Apr/07 7:12 AM
Field Original Value New Value
Assignee Juergen Hoeller [ juergen.hoeller ]
Fix Version/s 2.1 RC1 [ 10390 ]
Juergen Hoeller made changes - 17/Jul/07 5:39 PM
Fix Version/s 2.1 RC1 [ 10390 ]
Fix Version/s 2.2 RC1 [ 10552 ]
Arjen Poutsma made changes - 06/Nov/08 6:59 AM
Assignee Juergen Hoeller [ juergen.hoeller ] Arjen Poutsma [ arjen.poutsma ]
Arjen Poutsma made changes - 06/Nov/08 6:59 AM
Status Open [ 1 ] In Progress [ 3 ]
Juergen Hoeller made changes - 20/Nov/08 4:16 PM
Fix Version/s 3.0 M2 [ 10540 ]
Fix Version/s 3.0 M1 [ 10552 ]
Arjen Poutsma made changes - 22/Jan/09 5:18 AM
Status In Progress [ 3 ] Open [ 1 ]
Arjen Poutsma made changes - 22/Jan/09 7:12 AM
Status Open [ 1 ] In Progress [ 3 ]
Arjen Poutsma made changes - 22/Jan/09 9:56 AM
Status In Progress [ 3 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]

People

Dates

  • Created:
    13/Sep/06 11:35 AM
    Updated:
    22/Jan/09 9:56 AM
    Resolved:
    22/Jan/09 9:56 AM