Fix stuck thread on hashmap
https://issues.apache.org/jira/browse/TILES-599
Patch by shakeelabbas1
This closes #16


git-svn-id: https://svn.apache.org/repos/asf/tiles/framework/branches/TILES_3_0_X@1840290 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tiles-core/src/main/java/org/apache/tiles/preparer/factory/BasicPreparerFactory.java b/tiles-core/src/main/java/org/apache/tiles/preparer/factory/BasicPreparerFactory.java
index c9d46cd..e116c87 100644
--- a/tiles-core/src/main/java/org/apache/tiles/preparer/factory/BasicPreparerFactory.java
+++ b/tiles-core/src/main/java/org/apache/tiles/preparer/factory/BasicPreparerFactory.java
@@ -20,8 +20,10 @@
  */
 package org.apache.tiles.preparer.factory;
 
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.tiles.preparer.ViewPreparer;
 import org.apache.tiles.request.Request;
@@ -49,12 +51,14 @@
      * Maps a preparer name to the instantiated preparer.
      */
     protected Map<String, ViewPreparer> preparers;
+    protected Set<String> knownPreparers;
 
     /**
      * Constructor.
      */
     public BasicPreparerFactory() {
-        this.preparers = new HashMap<String, ViewPreparer>();
+        this.preparers = new ConcurrentHashMap<String, ViewPreparer>();
+        this.knownPreparers = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
     }
 
 
@@ -68,8 +72,12 @@
      */
     public ViewPreparer getPreparer(String name, Request context) {
 
-        if (!preparers.containsKey(name)) {
-            preparers.put(name, createPreparer(name));
+        if (!knownPreparers.contains(name)) {
+            knownPreparers.add(name);
+            ViewPreparer preparer = createPreparer(name);
+            if (preparer != null) {
+               preparers.put(name, preparer);
+            }
         }
 
         return preparers.get(name);