File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Caching an question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Caching an question." Watch "Caching an question." New topic

Caching an question.

Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
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?

[ June 30, 2005: Message edited by: Darrin Smith ]
leon fan

Joined: Aug 02, 2004
Posts: 19
I think so if you properly design that class. I guess you still need class lock for you function in which you will create your default icon.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

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.

I agree. Here's the link:
subject: Caching an question.
It's not a secret anymore!