aspose file tools*
The moose likes Servlets and the fly likes Caching an image...design question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Caching an image...design question." Watch "Caching an image...design question." New topic
Author

Caching an image...design 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?

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

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
Rancher

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.

Dave
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Caching an image...design question.