Index: components/session-pool/src/main/java/org/hippoecm/hst/core/jcr/pool/LazyMultipleRepositoryImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- components/session-pool/src/main/java/org/hippoecm/hst/core/jcr/pool/LazyMultipleRepositoryImpl.java	(revision 35737)
+++ components/session-pool/src/main/java/org/hippoecm/hst/core/jcr/pool/LazyMultipleRepositoryImpl.java	(revision )
@@ -57,6 +57,7 @@
     private ResourceLifecycleManagement [] lazyResourceLifecycleManagements;
     
     private ThreadLocal<Set<String>> tlCurrentCredsDomains = new ThreadLocal<Set<String>>();
+    private ThreadLocal<Map<String, Session>> tlCurrentSessions = new ThreadLocal<Map<String, Session>>();
     
     public LazyMultipleRepositoryImpl(Credentials defaultCredentials, Map<String, String> defaultConfigMap) {
         super(defaultCredentials);
@@ -172,7 +173,11 @@
     @Override
     protected Session login(CredentialsWrapper credentialsWrapper) throws LoginException, RepositoryException {
         Session session = null;
-        
+        if (tlCurrentSessions.get() != null && (session = tlCurrentSessions.get().get(credentialsWrapper.getUserID())) != null ) {
+            // for this thread, there is already a session created / retrieved for credentialsWrapper.getUserID()
+            // we can return this session directly
+            return session;
+        }
         try {
             PoolingRepository repository = (PoolingRepository) repositoryMap.get(credentialsWrapper);
             
@@ -209,15 +214,23 @@
         } else {
             credsDomains.add(credentialsDomain);
         }
-        
+
+        Map<String, Session> sessionMap = tlCurrentSessions.get();
+        if (sessionMap == null) {
+            sessionMap = new HashMap<String, Session>();
+            sessionMap.put(credentialsWrapper.getUserID(), session);
+            tlCurrentSessions.set(sessionMap);
+        } else {
+            sessionMap.put(credentialsWrapper.getUserID(), session);;
+        }
+
         return session;
     }
 
     private synchronized Session getSessionFromRepositoryCreatedOnDemand(CredentialsWrapper credentialsWrapper) throws Exception {
         Session session = null;
         PoolingRepository repository = (PoolingRepository) repositoryMap.get(credentialsWrapper);
-        
-        if (repository != null && !repository.isMarkedForDisposal()) {
+       if (repository != null && !repository.isMarkedForDisposal()) {
             session = repository.login(credentialsWrapper.getCredentials());
             setCurrentThreadRepository(repository);
             return session;
@@ -383,6 +396,11 @@
             Set<String> credsDomains = tlCurrentCredsDomains.get();
             if (credsDomains != null) {
                 credsDomains.clear();
+            }
+
+            final Map<String, Session> sessionMap = tlCurrentSessions.get();
+            if (sessionMap != null) {
+                sessionMap.clear();
             }
         }
         
Index: components/session-pool/src/test/java/org/hippoecm/hst/core/jcr/pool/TestLazyMultiplePoolingRepository.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- components/session-pool/src/test/java/org/hippoecm/hst/core/jcr/pool/TestLazyMultiplePoolingRepository.java	(revision 35737)
+++ components/session-pool/src/test/java/org/hippoecm/hst/core/jcr/pool/TestLazyMultiplePoolingRepository.java	(revision )
@@ -23,8 +23,10 @@
 import static org.junit.Assert.fail;
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 
@@ -161,6 +163,35 @@
     }
 
     @Test
+    public void assertSingleInstancePerThread() throws Exception {
+        ((LazyMultipleRepositoryImpl) multipleRepository).setTimeBetweenEvictionRunsMillis(5000);
+        ((LazyMultipleRepositoryImpl) multipleRepository).setDisposableUserIDPattern(".*;disposable");
+
+        Session session1 = multipleRepository.login(wikiCreds);
+        Session session2 = multipleRepository.login(wikiCreds);
+        Session session3 = multipleRepository.login(wikiCreds);
+        
+        assertTrue(session1 == session2 && session1 == session3);
+        
+        // assert the pool does not get exhausted either:
+        for (int i = 0; i < 500 ; i++)  {
+            multipleRepository.login(wikiCreds);
+        }
+        
+        // now for a new thread, we expect a different session.
+        List<Session> sessionHolder = new ArrayList<Session>();
+        Thread sessionCreationWithThread = new SessionCreationWithThread(multipleRepository,wikiCreds, sessionHolder);
+        sessionCreationWithThread.start();
+        sessionCreationWithThread.join();
+        
+        Session sessionFromThread = sessionHolder.get(0);
+        assertFalse(sessionFromThread == session1);
+
+    }
+    
+    
+    
+    @Test
     public void testAutomaticDisposing() throws Exception {
         ((LazyMultipleRepositoryImpl) multipleRepository).setTimeBetweenEvictionRunsMillis(5000);
         ((LazyMultipleRepositoryImpl) multipleRepository).setDisposableUserIDPattern(".*;disposable");
@@ -298,7 +329,31 @@
             }
         }
     }
+
+    @Ignore
+    private class SessionCreationWithThread extends Thread {
+
+        private Repository repository;
+        private Credentials credentials;
+        private List<Session> sessionHolder;
+
+        public SessionCreationWithThread(Repository repository, Credentials credentials, List<Session> sessionHolder) {
+            this.repository = repository;
+            this.credentials = credentials;
+            this.sessionHolder = sessionHolder;
+        }
+
+        public void run() {
+            try {
+                Session session = this.repository.login(this.credentials);
+                sessionHolder.add(session);
+            } catch (Exception ignore) {
+            }
+        }
+    }
+
+    
-
+    
     private void assertPoolProperties(Map<String, String> expectedPropMap, Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
         for (Map.Entry<String, String> entry : expectedPropMap.entrySet()) {
             String propName = entry.getKey();
