ImageIO.read 在多线程执行中抛出异常
我正在尝试使用 ImageIO.read 在多线程环境中从输入流读取图像。以下是代码,
entity = httpResponse.getEntity(); //httpResponse is apache hc response object
bufImage = ImageIO.read(entity.getContent()); //reading image
基本上,我使用 Apache HttpClient 创建 HttpConnection 并将图像作为流读取,然后将其转换为 BufferedImage(bufImage)。
这段代码在正常运行时工作正常。当我在多线程中运行它时,出现以下异常,
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 是我使用前面提到的 ImageIO 读取的行。我该如何解决这个问题?
谢谢, 阿比
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 ImgDownload.java:60 is the line which I read using ImageIO mentioned earlier. How do I solve this?
Thanks,
Abi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在 Ubuntu 12 上运行一个应用程序。
我已经安装了 libxtst6 并将此 java 参数添加到我的 JAVA_OPTS 变量中: -Djava.awt.headless=true
然后它工作正常。
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.
您是否在“生产”环境中使用不同的 JRE/JDK - 即当您在多线程环境中运行它时?类加载器引用的类是 Sun 特定的类 - 您是否在其他环境中使用 openjdk 之类的东西,或者您遇到错误?
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?