I am trying to use ImageIO.read to read an image from an input stream in a multi-threaded environment. Below is the code,
entity = httpResponse.getEntity(); //httpResponse is apache hc response object
bufImage = ImageIO.read(entity.getContent()); //reading image
Basically, I do an HttpConnection using Apache's HttpClient, and read the image as a stream, and then convert it to BufferedImage (bufImage).
This code works fine during normal operation. When I run it as in multiple threads, I get the following exception,
Exception in thread "Thread-3258" java.lang.NoClassDefFoundError: Could not initialize class sun.java2d.Disposer
at javax.imageio.stream.FileCacheImageInputStream.<init>(Unknown Source)
at com.sun.imageio.spi.InputStreamImageInputStreamSpi.createInputStreamInstance(Unknown Source)
at javax.imageio.ImageIO.createImageInputStream(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at com.example.ImgDownload.run(ImgDownload.java:60)
at java.lang.Thread.run(Unknown Source)
ImgDownload.java:60 is the line that I am reading using ImageIO mentioned earlier. How can i solve this?
Thanks Abi
source
share