By default, a single instance of your servlet will be created by the
container to service all requests.  The doGet() is not synchronized so
it must be written thread-safe.

Alternatively, you can have your servlet implement the SingleThreadModel
interface.  This instructs the container to create a pool of servlets
and synchronize access to them.

I do a lot of image generation from servlets, but since I have a
reasonably finite quantity of images I don't bother with
SingleThreadModel and just cache them in a synchronized HashMap.  The
overhead of creating the ImageBuffer, etc for the first instances is
small.

BTW, you might want to use the free Acme GIFEncoder
(http://www.acme.com) instead of Sun's jpeg encoder.  I believe the jpeg
encoder is only available in the Sun JVM and jpeg encoding is pretty
lousy for flat expanses of color anyways.

Jeff

>-----Original Message-----
>From: Huibert Aalbers Indaberea [mailto:[EMAIL PROTECTED]]
>Sent: Friday, March 30, 2001 9:53 AM
>To: Orion-Interest
>Subject: Servlet blues
>
>
>Hi everyone,
>
>I have written a servlet that dynamically generates an image 
>using Orion.
>Everything works fine under light load. However, under heavy load, when
>multiple users are using it simultaneously, it fails, 
>presenting erroneous
>data.
>
>Does every request instantiate a new servlet class or is the same one
>shared? Is the doGet method synchronized? Is this behaviour specific to
>Orion?
>
>In a related question, sometimes, under heavy load i get the following
>exception:
>
>    java.io.IOException: reading encoded JPEG stream
>    at sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream(Native
>Method)
>
>Has anyone seen this problem before?
>
>Thanks a lot for your help.
>
>Huibert
>
>
>

Reply via email to