Java ImageIO.write() takes up to 6 seconds

后端 未结 3 567
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 04:05

I am writing an web application where I need to send an image from servlet to client. Image is generated dynamically and is quite big(+-2MB). It might be jpeg, png, or gif.<

相关标签:
3条回答
  • 2020-12-22 04:27

    Image encoding in java is pretty slow in general but you may also want to ensure you have the native libraries installed as they make quite a noticeable difference in performance.

    http://download.java.net/media/jai-imageio/builds/release/1.1/INSTALL-jai_imageio.html

    0 讨论(0)
  • 2020-12-22 04:28

    Be aware that ImageIO by default uses temporary files as cache when creating ImageInputStreams and ImageOutputStreams. This can be switched off by calling ImageIO.setUseCache(false).

    For a more detailed explanation see this answer.

    0 讨论(0)
  • 2020-12-22 04:31

    Are you sure that the

    ImageIO
    

    takes so long - maybe there is another problem, e.g.

    • slow (network) connection to the client
    • the generation (calculation) of the image takes a lot of time
    0 讨论(0)
提交回复
热议问题