wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Safely reloading object cache while possible multiple clients using Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Safely reloading object cache while possible multiple clients using "old" objects." Watch "Safely reloading object cache while possible multiple clients using "old" objects." New topic
Author

Safely reloading object cache while possible multiple clients using "old" objects.

Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
I'll attempt to explain this a clearly as possible.
Requirements:
1) A JSP tag library that serves language localized UI objects for company Web applications.
2) Information that generates these objects is provided via the parsing of xml files read in from the local file system (via UrlClassLoader).
3) In order to minimize footprint, only one instance of the DataServer object module must be shared across all session instances (possibly thousands).
4) Object server content must be dynamically reloadable upon,
a) A configurable timer that when run sets a flag to indicate that the xml file source needs to be checked for updates during the next access.
b) next access after flag is checks a date stamp in the xml file(s) and if different then the prior access, refreshes the cache of the singleton DataServer instance.

So a typical SimpleTag process would do something like this:

(pseudo SimpleTag code):



seems simple enough... however, the obvious issue for me in this case is after the ds.getSomeObjectList() is performed and the objects are in the process of being sent to the session space and then rendered via the JSP client code in one client, another client wanting this same DataServer comes in... and during this access it is deemed necessary to reload the object cache as per the rules stated above. If this should happen the objects that the first client is processing are deleted due to the cache refresh and all hell is to be paid.

This has to be a relatively common problem with possibly many approaches to guarantee the integrity if the DataServer objects across multiple clients?
Personally I can come up with no logical solution to absolutely guarantee that at no particular time a referenced object will become unglued due to the dynamic reloading requirement.

Can anyone provide suggestions on how to approach this? Other then coming up with an elaborate access counting algorithm which would be very difficult to support, I'm at a loss as to what to do about this.

regards,
Karl





[SCJP 6]
[SCBCD in process]
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 503
    
    4

What do you consider the problem with that object becoming detached when the cache is refreshed?


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
Dieter Quickfend wrote:What do you consider the problem with that object becoming detached when the cache is refreshed?


Hi Dieter,
I would think somewhat obvious, but if the original object that was returned was being referenced for contained properties by client 1 and it was unexpectedly deleted by a second client process during this event wouldn't/couldn't it result in a null pointer (or some other reference exception) condition? or should the GC not allow the deletion since it's being referenced by another thread?

~Karl
Karl Krasnowsky
Ranch Hand

Joined: Jan 16, 2009
Posts: 97
Karl Krasnowsky wrote:but if the original object that was returned was being referenced for contained properties by client 1 and it was unexpectedly deleted by a second client process during this event ...


I guess it's not technically deleted by the update process, simply replaced, so the original should still be accessible by the initial client undisturbed until its reference is released? I guess I'm looking at this as if I'm modifying the same object, but essence this isn't the case. I also think I'm using the term "guess" too much. Makes me nervous.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Safely reloading object cache while possible multiple clients using "old" objects.
 
Similar Threads
J2EE Recommended Reading
Passed IBM 483
IBM 483 (ICE Test)
please answer these sun j2ee test questions
My SCEA Part 1Study Notes