glassfish 3.1.1 上带有线程的 Web 服务

发布于 2024-12-24 03:55:45 字数 261 浏览 2 评论 0原文

我有一个用 spring 3 和 struts 2 编写的 web 应用程序,托管在 glassfish 服务器上。在这个应用程序中,我有两个网络服务需要做一些后台工作而不延迟访问的方法响应。

所以,现在我使用一个 spring bean,它使用 org.springframework.core.task.TaskExecutor 的实例,然后从那里运行我的新线程。

在 glassfish 上使用此应用程序时,这是正确/最佳实践方法吗?或者应该找到另一种方法来做到这一点?

i have a webapp written with spring 3 and struts 2 that is hosted on a glassfish server. In this app i have two webservices that need to do some background work without delaying the accessed method response.

So, now i use a spring bean that uses an instance of org.springframework.core.task.TaskExecutor and from there i run my new thread.

Is this the correct/best practice approach in context of using this app on glassfish? or should find another method of doing this ?

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

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

发布评论

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

评论(1

看透却不说透 2024-12-31 03:55:45

不鼓励创建自己的线程,因为应用程序服务器应该负责。请参阅为什么不鼓励在 Java EE 容器中生成线程?

但是在实践中,特别是如果它是那里唯一的应用程序,您可能没问题,特别是如果您使用固定线程池。确保取消部署应用程序时所有线程都消失了。 (我希望 Spring 类能够正确处理取消部署/关闭的处置,如果您在 Spring 容器中声明它们)。

It's discouraged to create your own threads because the app server is meant to be in charge. See the answers to Why is spawning threads in Java EE container discouraged?

However in practice, especially if it's the only application on there, you might be OK, especially if you use a fixed thread pool. Be sure all the threads are gone when you undeploy the app. (I expect Spring classes will handle disposal on undeploy / shutdown correctly, if you declare them within the Spring container).

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