The moose likes Groovy and the fly likes storing a map in servletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "storing a map in servletContext" Watch "storing a map in servletContext" New topic

storing a map in servletContext

Maharaj thak

Joined: Jul 29, 2010
Posts: 27
Hi All
I have a map stored in the servletContext.Will there be a slowness in performance if I access those variables in my .gsp files?Data from the map is read more than written to it.

Mauji thak
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

I don't think performance, so to speak will be your big problem. Yes it can be affected by the big problem that might occur storing a mutable Map in the ServletContext. And this has nothing to do with Groovy or Grails. So the ServletContext is a single instance per web application. So it is shared across the entire web application, and therefore many threads might be trying to read/update that one single Map you have stored. So now you have to make sure that your Map reading/writing is done in a threadsafe manner. That part of maybe having to synchronize on the Map or worse the ServletContext, that you might have contention and therefore slow down performance.

However, that is also not to say that 100% of the time this is a bad idea. It all depends.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: storing a map in servletContext
It's not a secret anymore!