[jboss-user] [JBoss Seam] - Seam messages and containsKey

damianharvey do-not-reply at jboss.com
Wed Oct 31 08:25:39 EDT 2007


I had a bit of a performance problem with some pages that I have tracked back to my use of '.containsKey()' on the Seam messages Abstract Map.
eg:
  | @In 
  | Map<String, String> messages; //This is the Seam messages bundle
  | 
  | public void aMethod() {
  |    if(messages.containsKey("key.mykey")) {
  |        //do something
  |    }
  | }
  | 
As containsKey isn't a method of the AbstractMap in org.jboss.seam.international.Messages, it goes into a mad run through all sorts of methods (ELResolver, Pages.java etc). The result of this is that a containsKey() on messages takes over 800 times longer than a get(). For 1800 properties in my messages.properties file it takes about 800ms compared to under 1ms for a get().

Nice to have found this as I had no idea that it would have such an impact. The easy solution would be to add a containsKey() to the AbstractMap in org.jboss.seam.international.Messages. This works well for me (and is under 1ms):

  | 	public boolean containsKey(String key) {
  | 		if(messages.get(key).equals(key)) {
  | 			return false;
  | 		} else {
  | 			return true;
  | 		}
  | 	}
  | 

Cheers,

Damian.


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

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4100622



More information about the jboss-user mailing list