Author: alessio.soldano(a)jboss.com
Date: 2009-11-30 04:35:36 -0500 (Mon, 30 Nov 2009)
New Revision: 11168
Modified:
common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
Log:
[JBWS-2847] Caching props in EntityResolver
Modified: common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java
===================================================================
---
common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java 2009-11-29
16:18:32 UTC (rev 11167)
+++
common/trunk/src/main/java/org/jboss/ws/core/utils/JBossWSEntityResolver.java 2009-11-30
09:35:36 UTC (rev 11168)
@@ -27,8 +27,12 @@
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.Map;
import java.util.Properties;
+import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
import org.jboss.logging.Logger;
import org.jboss.util.xml.JBossEntityResolver;
@@ -43,6 +47,12 @@
*/
public class JBossWSEntityResolver extends JBossEntityResolver
{
+ /**
+ * A synchronized weak hash map that keeps entities' properties for each
classloader.
+ * Weak keys are used to remove entries when classloaders are garbage collected;
values are filenames -> properties.
+ */
+ private static Map<ClassLoader, Map<String, Properties>> propertiesMap =
Collections.synchronizedMap(new WeakHashMap<ClassLoader, Map<String,
Properties>>());
+
// provide logging
private static final Logger log = Logger.getLogger(JBossWSEntityResolver.class);
@@ -54,12 +64,28 @@
public JBossWSEntityResolver(final String entitiesResource)
{
super();
-
- // load entities
- Properties props = loadEntitiesMappingFromClasspath(entitiesResource);
- if (props.size() == 0)
- throw new IllegalArgumentException("No entities mapping defined in resource
file: " + entitiesResource);
+ Properties props = null;
+ ClassLoader loader = this.getClass().getClassLoader();
+ Map<String, Properties> map = propertiesMap.get(loader);
+ if (map != null && map.containsKey(entitiesResource))
+ {
+ props = map.get(entitiesResource);
+ }
+ else
+ {
+ if (map == null)
+ {
+ map = new ConcurrentHashMap<String, Properties>();
+ propertiesMap.put(loader, map);
+ }
+ // load entities
+ props = loadEntitiesMappingFromClasspath(entitiesResource);
+ if (props.size() == 0)
+ throw new IllegalArgumentException("No entities mapping defined in
resource file: " + entitiesResource);
+ map.put(entitiesResource, props);
+ }
+
// register entities
String key = null, val = null;
for (Enumeration<Object> keys = props.keys(); keys.hasMoreElements();)
Show replies by date