-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Konstantin,

On 7/13/2011 6:53 PM, eurotrans-Verlag wrote:
> Thanks. In the meantime, I also came to that conclusion and replaced
> all instances of
> 
> ImageIO.write(img, "PNG", response.getOutputStream())
> 
> in my servlets/webapps with something like
> 
> ByteArrayOutputStream bout = new ByteArrayOutputStream(); 
> ImageIO.write(img, "PNG", bout); 
> bout.writeTo(response.getOutputStream());
> 
> so that the ImageIO never sees the real OutputStream, and it seems to
> work fine (no more IllegalStateExceptions or "wrong message format"
> errors in the isapi log when using AJP-APR).

Wow, I'm surprised that had an effect. Or, rather, I'm surprised that
ImageIO doesn't have decent object reference management.

> Is that a good practice (using ByteArrayOutputStream, then copy it to
> the response) to dynamically generate Images and serve them to the
> clients?

There is a downside: you need a bunch of temporary memory available to
perform these image manipulations. ImageIO uses a lots of memory
already, and now you are going to have to buffer the entire output image
before the first byte is written back to the client. That means no
streaming whatsoever, which might strain your resources.

You might want to look at your heap size, average image size, and
estimated user load to determine if you want to do something like put a
hard limit on the number of image transformations that can be performed
simultaneously. Otherwise, you risk OOME.

> Also, is there any hint to this on the Tomcat documentation/wiki?
> Because I don't think it would be unusual to dynamically generate
> images and serve them to clients using the ImageIO, and I think it
> could be a bit frustrating to find the actual problem if one doesn't
> know this.

Tomcat obviously can't document all foreign API problems out there, but
it might be worth mentioning this one on the Wiki somewhere. Feel free
to create a wiki account and create a new page for these kinds of things.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4u5yMACgkQ9CaO5/Lv0PDMGQCfSLZ1BpdK7GVqd5wh+ZjYzFTA
H50AoIzjIoX6r72h4k1/VMLLqBjNPSI8
=V6o8
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to