File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Refresh a Singleton Object values 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 » Servlets
Bookmark "Refresh a Singleton Object values" Watch "Refresh a Singleton Object values" New topic
Author

Refresh a Singleton Object values

Ansa Suseelan
Greenhorn

Joined: Apr 09, 2008
Posts: 3
HI,
I am woring on a MOM system, where we load the application specific values from an XML file thru a servlet init() method during the application start up time and put into a hashtable with key-value pair. A Singleton class is created to access these values. Now i want to change the xml file and refresh the hashtable with the new values without restarting the server. Is there any option to do it?
Thanks,
Ansa


-Ansa
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Does your singleton object's class provide a method to refresh or re-read the xml file?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ansa Suseelan
Greenhorn

Joined: Apr 09, 2008
Posts: 3
No, the class contains methods such as put,get,add and remove objects, which inturns calls another class which extends Hashtable. It is possible to clear all the contents and create the new instance by manually. But i want this to be done automatically whenever/immediately the file get changed.
Thanks,
Ansa
[ April 17, 2008: Message edited by: Ansa Suseelan ]
bala nagireddy
Greenhorn

Joined: Dec 26, 2006
Posts: 2
You have a a logic in the singleton class like whenver someone tries to get the any value from hashtable you can check whether the file contents are changed before returning the value and then update the hashtable and then return the new value.
Ansa Suseelan
Greenhorn

Joined: Apr 09, 2008
Posts: 3
Thanks, the logic sounds ok, but this will affect the performance !!! In this logic we will have to check the file property each time we access the hashtable. As I have mentioend earlier its a MOM system processing >1M records daily. Is there any listener available for file change or folder change?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refresh a Singleton Object values
 
Similar Threads
How to write a XML, in Java
how to solve this
Object Passing & File I/O on a Cluster
How to refresh a portlet automatically
Singleton Thread Safety