wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "storing a map in servletContext" Watch "storing a map in servletContext" New topic
Author

storing a map in servletContext

Maharaj thak
Greenhorn

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.

Regards
Mauji thak
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: storing a map in servletContext
 
Similar Threads
How to Create a Phone Book with Java?
What did you get this Christmas?
Best Internet application
Elections at JavaRanch ?
Converting user inputs to enum constants