Aditya K
Aditya K

Reputation: 487

Sharing HashMap across a JSP app in a clustered environment

Ours is a JSP/JSF based app that runs on Weblogic 10 (clustered in production). We have a scenario where the (logged in) user acquires a timestamp based lock on an object. After acquiring the lock, a code runs every 60 seconds to renew/invalidate the lock. Currently the lock details are maintained in the database. Meaning, every 60 seconds, to renew the lock, an update query is fired.

We are trying to move this logic at the application layer where we can avoid hitting the database. For that, the data that was earlier written to the DB is now maintained in a HashMap. However, the HashMap is stored in the ServletContext object. For acquiring a lock for a new user, the HashMap is acquired from the ServletContext object and any operations are then done on it.

However, it just came to light that ServletContext objects are not replicated across clusters. So if I have a HashMap that is changed in say, node-1 when user-1 acquired lock to object-1, and user-2 logs in, tries to acquire a lock to object-1 but the request hits node-2, I guess, the logic would fail, right? Because node-2 won't have the updated HashMap.

Any idea/Suggestions? Please help.

Thank you, A

Upvotes: 3

Views: 669

Answers (1)

Rahul Agrawal
Rahul Agrawal

Reputation: 8971

Yes, we did similar thing for one of our project, sharing ServletContext amongst all clustered nodes on weblogic server

Check below parameter for weblogic

coherence-servletcontext-clustered

Either true or false to indicate whether the attributes of the ServletContext will be clustered. If true, then all serializable ServletContext attribute values will be shared among all cluster nodes.

If unspecified, defaults to false, primarily because the Servlet specification indicates that the ServletContext attributes are local to a JVM and should not be clustered.

For more details refer http://docs.oracle.com/cd/E13924_01/coh.340/e14408/appparams.htm

Upvotes: 1

Related Questions