SeekableStream 线程安全吗?

发布于 2024-12-08 13:27:56 字数 960 浏览 0 评论 0原文

我有一个应该调整图像大小的程序。当我单独运行它时(从 JUnit 调用),它工作得很好。但是,当我从servlet(实际上是JUnit中的Jersey)内部调用它时,它会抛出以下异常:

SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NoClassDefFoundError: com/sun/media/jai/codec/SeekableStream

异常指向行

SeekableStream seekableImageStream = SeekableStream.wrapInputStream(inputstream, true);

Doesanybodyhaveanyfix?

在下面的一些响应之后进行澄清:

当我按如下方式从 JUnit 调用该类时,它会起作用: ResizeMyImage.smallImage(imageFilepath,thumbnailWidth);

但是,当我按如下方式调用它时,会收到错误:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);

如果我从较大的程序中删除对 ResizeMyImage 的调用,则 DefaultHttpClient ... 也可以工作。谢谢。

回应以下问题:如何验证 GlassFish 使用的是不同的 JDK?

I have a program that is supposed to resize an image. When I run it alone (call from JUnit), it works fine. But when I call it from inside a servelet (actually Jersey in a JUnit), it throws the following exception:

SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NoClassDefFoundError: com/sun/media/jai/codec/SeekableStream

The exception points to the line

SeekableStream seekableImageStream = SeekableStream.wrapInputStream(inputstream, true);

Does anyone have any fix?

TO CLARIFY AFTER SOME RESPONSES BELOW:

When I call the class from JUnit as follows it works:
ResizeMyImage.smallImage(imageFilepath, thumbnailWidth);

But when I call it as below, then I get the error:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);

If I remove the calls to ResizeMyImage from the larger program, the DefaultHttpClient ... works as well. Thanks.

Response to below: How do I verify that GlassFish is using a different JDK?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我纯我任性 2024-12-15 13:27:56

如果您有来自两个不同线程的对象引用,则只需担心该对象是否是线程安全的。如果它不是线程安全的,那么当两个不同的线程尝试同时使用该对象时,您将会遇到问题。

正如其他人指出的那样,NoClassDefFoundError 意味着 java 找不到您在代码中引用的类。

编辑

JAI 做一些事情很糟糕。 sanselan 等库可能更适合您。

You only have to worry about an object being thread-safe if you have a reference to the object from two different threads. If it's not thread-safe you will have problems when two different threads try to use the object at the same time.

As others have pointed out NoClassDefFoundError means java can't find a class you are referencing in your code.

EDIT

JAI stinks for doing some things. A library such as sanselan may work better for you.

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