You could avoid creating a thread by implementing a freshness check at an access point. That is, rather than having your action get its config out of the servletcontext, have it get a plug-in instance out of the servlet context, and have it ask the plug-in for the config. At that time, the plug-in can decide whether it needs to reload the config or not before returning it to the action, perhaps by comparing the last modified timestamp on the config file to a value stored the last time the file was read.
Then you could just add a "synchronized" modifier to the plug-in method that the action classes call and achieve pretty simple thread safety. It's not the fanciest, but if you're not comfortable writing concurrent code, better safe than fancy!
Joe
> I need to do something similar with additional configuration properties fora particular action.
I figure I need to write a plug-in that creates a thread that checks the properties file every x seconds and if changed reloads it into a context attribute.
My problem is I've never done thread-safe programming before and I figure I need to handle the possibility that the plug-in's thread could be writing a new version while several actions are reading from the existing one.
Does anyone have any pointers to some information on how to do this properly? Much appreciated.
Just a thought:
How about extending the ActionServlet and maintain an "expire"-variable that is set at init-time. Then every time after a request is processed the expire variable is checked. If expired, calls the same method for loading the resources as init() does (think it's initModuleMessageResources)?
--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "We want beef in dessert if we can get it there."
-- Betty Hogan, Director of New Product Development, National Cattlemen's Beef Association
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]