ImageIO.read 在多线程执行中抛出异常

发布于 2024-11-15 14:22:39 字数 974 浏览 3 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北方。的韩爷 2024-11-22 14:22:39

我正在 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.

风透绣罗衣 2024-11-22 14:22:39

您是否在“生产”环境中使用不同的 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文