Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-2581

Provide out of the box implementation of the thread scope

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0 final
    • Fix Version/s: 3.0 M2
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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) {
        }
        
      }
      

        Attachments

          Activity

            People

            Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            euxx Eugene Kuleshov
            Last updater:
            Spring Issues
            Votes:
            16 Vote for this issue
            Watchers:
            22 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 2 weeks ago