|
-
November 9th, 2010, 10:15 AM
#1
Named locks (mutexes)
Hi everyone,
I'd like to run a design by you and ask on how to implement it. Here is the basic problem:
I have a servelet A that returns full JPG images.
I have a servelet B that returns JPG images that are only parts of the images.
(e.g. the whole image is 1600x1200 and servelet B returns only the upper right corner 400x400 part of the image).
The filesystem on the server stores a TIFF master file for the full image.
When servelet A is called, it checks whether a copy of the JPG exists in a cache (EhCache), and if it does, this is returned. Otherwise, the TIFF is converted to JPG, put into the cache and delivered.
When servelet B is called, it also checks whether a copy of the JPG exists in a cache and if it does, it cuts part of the image out and delivers it. Otherwise, the TIFF is converted to JPG, the whole JPG is saved in the cache, the part is cut out and delivered.
The main concurrency problem here is that when A or B is in the process of creating the JPG from the TIFF, the other (or even the same) servelet should not be able to read from it. This is file-specific. I.e. if aaaaa.tiff is being converted, another instance can still convert bbbb.tiff at the same time.
My naive idea is to wrap the conversion part in a mutex, where I say something like:
getLock(filename);
// do conversion
releaseLock(filename);
So if the lock has the same name as filename, my condition would work. Is there a type of locking in Java that can be made to work like this?
I've looked at java.util.concurrent.locks (http://download.oracle.com/javase/1....e-summary.html), but haven't figured out a way to use this to do what I want.
Any help is appreciated,
Yves
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|