tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: AJP-APR failures on Tomcat 7.0.16 with ISAPI Redirector 1.2.32
Date Tue, 26 Jul 2011 16:11:15 GMT
Hash: SHA1


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
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


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

View raw message