This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a servlet that reads up imaages from a databasae and sends them back to my web app. If a requested image does not exist, I send back a common default image.
My question is about caching this default image.
Is there any problem with making an ImageIcon static, and checking to see if it contains data (is null or not), and if it does hold data, just return its contents, and if it is null, have it read up the default image for the first time?
Need I lock this "null check" code down or should it be "OK" not to do so since it is a static object that will be set to the same value regardless?
Thanks! [ June 30, 2005: Message edited by: Darrin Smith ]
I'd consider reworking the solution to allow a static image to be served rather than hitting the servlet, if possible. When you build the initial page, change the image location to the servlet or an image on the file system if that servlet image doesn't exist, it'll be worth it in the long run.