I have a resource file that I need loaded into a Bean that is made available for my entire web app. I was wondering what the best way to do this is and most efficient way.
Should I load it when the application server starts (Tomcat)?
Should I load it when the first request is made to the app?
Should I just read the resource file and not worry about a bean every time?
Thanks for any help. Depending on the response, I will probably have follow up questions on how to implemenet it.
Hope this helps.
Thus, I tend to use a lazy initialization technique, where if the information doesn't exist, it gets loaded. I'll put all the related information into a single object and then store a static reference to that object. When I access the information, if the reference is null, I load the information. With this technique, reloading is as simple as clearing the object reference.
Originally posted by Gregg Bolinger:
Joe, sounds like a singleton approach. The only problem I have with your solution is I don't want to have to check for that object everytime I need it. I want to expect it to just be there. That is why I would prefer to load it when the app starts and just put it in the ServletContext. Is this a bad idea?
A man after my own heart. Does it cost too much to check for the value every time? Of course, you could put in a try/catch for null pointer exception; I wonder if that would have the same overhead? Anyway, at this point it's purely an implementation question. From a design standpoint, I think the various techniques are equivalent.