ImageIO.read throws exception in multithreaded execution
I am trying to use ImageIO.read to read image from inputstream in a multithreaded environment. The following is the code,
entity = httpResponse.getEntity(); //httpResponse is apache hc response object
bufImage = ImageIO.read(entity.getContent()); //reading image
Basically, I am making an HttpConnection using Apache HttpClient and reading an image as stream, then converting it to BufferedImage(bufImage).
This code works fine when run normally. When I run it as in multiple threads, I am getting 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)
The I开发者_运维百科mgDownload.java:60 is the line which I read using ImageIO mentioned earlier. How do I solve this?
Thanks, Abi
I'm running an app in one Ubuntu 12.
I've installed libxtst6 and add this java parameter to my JAVA_OPTS variable: -Djava.awt.headless=true
Then it works fine.
is it the case that you are using a different JRE/JDK in your "production" environment -- i.e. when you run this in a multi-threaded environment? the class the classloader is referring to is a sun specific class -- are you using something like openjdk maybe in the other environment you're getting the error in?
精彩评论