[jboss-user] [JNDI/Naming/Network] - Re: Slow JMS destination lookup
mohitanchlia
do-not-reply at jboss.com
Tue May 19 19:38:46 EDT 2009
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
More information about the jboss-user
mailing list