Below is the code. I have timing around the code and only piece that's slow is 
when there is a ctx.lookup involved.

  |     private Object lookupJndi(String jndiName) {
  |         Object result = null;
  | 
  |         try {
  |             result = ctx.lookup(jndiName);
  |         } catch (NamingException e) {
  |             throw new ServiceLocatorException("JNDI lookup error while 
looking up resource: '" + jndiName + "'", e);
  |         }
  |         return result;
  |     }
  | 

  | cache = Collections.synchronizedMap(new WeakHashMap<String, Object>());
  | 

  |     public Object lookup(String jndiName, boolean useCache) {
  |         Object result = null;
  |         long t1=System.currentTimeMillis();
  |         if (useCache) {
  |             if (cache.containsKey(jndiName)) {
  |                 result = cache.get(jndiName);
  |             }
  |             
  |             // WeakHashMap can return null
  |             if (result == null) {
  |                 result = lookupJndi(jndiName);
  |                 logger.info(jndiName + " Lookup took " + 
(System.currentTimeMillis() - t1));
  |                 t1=System.currentTimeMillis();
  |                 // we need to make copy of the key
  |                 // as the original one can be a literal from the
  |                 // String pool which prevents it from being garbage 
collected
  |                 // and our WeakHashMap working
  |                 cache.put(new String(jndiName), result);
  |                 logger.info(jndiName + " Lookup insert in cache took " + 
(System.currentTimeMillis() - t1));
  |                 t1=System.currentTimeMillis();
  |             }else{
  |                 logger.info(jndiName + " Lookup from cache took " + 
(System.currentTimeMillis() - t1));
  |                 t1=System.currentTimeMillis();                
  |             }
  |         } else {
  |             result = lookupJndi(jndiName);
  |             logger.info(jndiName + " Lookup took " + 
(System.currentTimeMillis() - t1));
  |             t1=System.currentTimeMillis();
  |         }
  |         return result;
  |     }
  | 

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4232070#4232070

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4232070
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to