Edwin Stephens wrote:Although I've heard the ServletContextListener way is more proper, I tend to use a servlet's init() method, since I can control when the servlet is loaded (via load-on-startup) in relation to other servlets, so that config data can be initialized before other servlets need that data.
Context listeners are run before any servlet is initialized, so that shouldn't be an issue. While the load-on-startup technique works fine, for new development I'd recommend to use context listeners instead. Having a servlet just for initializing stuff -which is not actually being called- is kind of a hack.
Ruben Matthews wrote:@Edwin: that is a good point you're making about the app servers. I am not sure how I would deal with this. Is clearing each app server by requesting a JSP at each server a good idea? Or would that be that ugly?
I'd say that's a hack one wouldn't want to keep in place long term. But generally, if you have an application that's used on multiple servers, then it's time to centralize those config settings (in a DB), and provide a GUI for them so that they can be edited at runtime (where applicable).
You could put a timestamp into the config table, and have the app servers periodically check that. Then they'd reload the settings if the timestamp is newer than the config data they're currently using.