Most of my jsp pages will get the cached data from this object. I am just wondering, will those jsp pages (in visitors' machine viewing my website) be affected fatally* when I (as an admin) performed a reload() call to update the hashtable inside this object/servlet?
*fatal as in causing a servlet exception during the reloading process, perhaps?
If there are possible risk of exception, what is the best practice to handle such methods of caching? [ December 05, 2007: Message edited by: Alan Yap ]
You don't want to try to bind the servlet itself to application scope. In fact that won't work. You'll end up with two instances of your class, one created by the container and a second created by the useBean tag.
If all you want to do is make a HashMap available, you can simply bind it to application scope. You can do his from a servlet or from a contextListener when the application starts.
From your reply, does this means if the hashtable is storing 1kb of data, my method above would consume twice the memory size? (as 2 instances are created). I have no problem reloading the hashtable but I'm scared during high traffic volume of my site, performing a reload to my application scoped data will caused the jsp page failed to be rendered at the same time.
Would an application scoped Hashtable be equally effective as a hashmap? Hence..
Well besides having some data be stored inside the hashtable (inside my application servlet), I will be storing another set of data inside some arrays too (with size up to 200 items per array).
My point is that a servlet is an object that listens for web requests and responds to them. It is not a datastructure that you would bind to scope.
If you need your hashtable to be available to all objects in the application then bind it to context scope. Don't make it an instance variable in a servlet and certainly, don't try to bind a servlet to any of the scoped objects.
Joined: Feb 24, 2006
thanks! things are getting clearer now.
I found out that I've been using the wrong "implementation" in my codes
Any comments if I made it a serializable object instead?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com