tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joseph Morgan" <>
Subject RE: storing images
Date Fri, 06 May 2011 14:09:29 GMT

We do this exact same thing all the time.  I solve the concurrency on
the image problem by adding a small session hash value to the image
name.  It does mean we may get 10 of the same images if 10 concurrent
access are happening, but it also allows us clean things up without
worry of destroying an image someone is using.

-----Original Message-----
From: alexis [] 
Sent: Friday, May 06, 2011 8:38 AM
To: Tomcat Users List
Subject: Re: storing images

Image is built using a jfreechart object, once created it's stored as
attribute in servletcontext, at this stage image is complete before the

What im not sure if setattribute is synchronized, if not i can
synchronize the method that creates and store the image.

Enviado desde blackberry

-----Original Message-----
From: sebb <>
Date: Fri, 6 May 2011 14:05:14 
To: Tomcat Users List<>
Reply-To: "Tomcat Users List" <>
Subject: Re: storing images

If multiple threads try to create the image at the same time it is
possible that one thread will see a partial file - or the file may be

If you are not doing this already, I suggest creating the file with a
unique temporary name and then renaming it once complete.
The rename may fail if another thread has meanwhile created it, but
that can easily be allowed for.

Trying to lock the file whilst it is created is likely to be harder to
implement; however it might be worth it if the file creation is very
expensive in system resources.

On 6 May 2011 13:48, Thad Humphries <> wrote:
> I'd store the image to and retrieve it with a servlet.
> doing this now with my Ajax application.
> On Thu, May 5, 2011 at 2:19 PM, alexis <> wrote:
>> Hello all, im facing an issue, ive been testing for a while different
>> approaches without success.
>> I have a servlet that basically does
>> . creates an image
>> . store the image on disk
>> . returns an html <img> tag pointing to the stored image.
>> reason why the servlet doesnt returns the image directly using a
>> type image/png is the servlet is called from an ajax script, this
>> script renders the inner text inside a div on a jsp page on the same
>> that the server runs. ajax can only render html on divs, there's no
way to
>> return binary content (the image) from the servlet to the ajax
>> So, i have to create the image on the servlet (done) , store the
image on
>> the disk (done), and return the <img> tab also done. Thing is, where
im able
>> to store the image from the servlet im not able to read it from the
>> I tried with /tmp, i tried with servletcontext.getpath to store the
file on
>> that dir, nothing seems to work. where should i store and reference
>> images to be written by the servlet and read by the jsp?
>> thanks in advance
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> --
> "Hell hath no limits, nor is circumscrib'd In one self-place; but
where we
> are is hell, And where hell is, there must we ever be" --Christopher
> Marlowe, *Doctor Faustus* (v, 121-24)

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message