且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Java EE中启动多个线程?

更新时间:2023-12-03 22:44:10

在一个内部创建自己的线程通常不鼓励使用应用程序服务器,因为服务器应该管理线程以获得更好的可伸缩性。如果容器对线程上下文中可用的内容做出假设,例如安全信息(例如,经过身份验证的主题),则也会遇到问题。如果你生成一个线程,然后使用该容器未知的服务器资源,通常会发生这种情况。

Creating your own threads inside an application server is generally discouraged because the server should manage threads for better scalability. You can also run into problems if the container makes assumptions about what's available in a thread context, such as security information (e.g., authenticated Subject). That typically happens if you spawn a thread and then use a server resource from that thread which is unknown to the container.

检查是否有办法获取容器来自Tomcat的托管线程。 WebLogic和WebSphere支持commonj.WorkManager,它允许您安排容器管理线程的工作。 Spring也可以使用commonj,但我不确定Tomcat上是否有这种支持。

Check to see if there is a way to get container managed threads from Tomcat. WebLogic and WebSphere support the commonj.WorkManager, which allows you to schedule work on container managed threads. Spring can also use commonj, but I'm not sure if that support is available on Tomcat.