This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a J2EE application which stores an object in the servlet context using set attribute. This object basically maintains a collection of objects (of a different type) in a specific order and provides access to them. The problem is that this application is now being deployed into a clustered WAS environment, and the servlet contexts will not be shared among the servers. What would be the easiest way to address this?
Thanks for your help Jeanne. The problem is this. I am storing an object called SideBar in the servlet context. This Sidebar object provides access to Category objects which are stored in a tree. At runtime servlets get the SideBar object and then ask for all the Categories to be displayed. The problem occurs when a servlet updates a Category, which could change its order in the tree or other internal data. This update changes the objects in memory and writes to storage, but the updates are only updating the SideBar/Category in their own container, so the other servers get out of synch.
You'll need some kind of distributed cache scheme. For example, the node that does the update can broadcast a JMS message that tells the others to remove the data from the cache. The next time somebody asks for the data they can fetch it from storage and put it back in the cache. Google for "java distributed cache" for lots more info.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
author & internet detective
Originally posted by Stan James: You'll need some kind of distributed cache scheme.
Command caching is IBM/WebSphere's proprietary scheme for this. It is available in WebSphere 5 and up.
Steve, Your scenario is roughly in line with what I was thinking about. You may need to refactor the cache to be behind a java class or its own servlet rather than in the context though.
Joined: Apr 19, 2004
So would implementing command caching be less of a change than going with entity beans? Please keep in mind, that I have no experience with enterprise beans or command caching, and at this point I am looking for a reliable yet relatively easy solution. Thanks in advance.