Java 应用程序线程创建
Java application thread creation
我正在开发 java 应用程序。我们正在使用 Spring 并且应用程序运行 WebSphere 应用程序服务器。在整个应用程序中,我们使用 Spring 维护在应用程序中创建的多个线程池。就像下面一样,到目前为止我们还没有遇到任何问题。
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="maxPoolSize" value="100"/>
<property name="corePoolSize" value="10"/>
</bean>
但我在阅读 Spring 框架参考文档时遇到了下面的段落,
34.3.3 TaskScheduler implementations
As with Spring’s TaskExecutor abstraction, the primary benefit of the
TaskScheduler is that code relying on scheduling behavior need not be
coupled to a particular scheduler implementation. The flexibility this
provides is particularly relevant when running within Application
Server environments where threads should not be created directly by
the application itself. For such cases, Spring provides a
TimerManagerTaskScheduler that delegates to a CommonJ TimerManager
instance, typically configured with a JNDI-lookup.
ref.
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html
所以我的问题是,如果我不关心访问 Java EE 上下文信息,还有哪些其他原因需要使用托管线程池?
我基本上想知道那里的最佳实践是什么,以及是否让应用程序管理线程是完全不可接受的。
通常,WebSphere 等企业服务器上的线程池(以及 JDBC 连接)不应由应用程序管理,而应由服务器本身管理。 Spring 仅提供您的应用程序和服务器线程池模型之间的接口。
在服务器端配置线程池的主要好处是效率:在过去,多个应用程序通常部署到同一台服务器上。使用共享线程池可以利用服务器的所有资源。如今,将多个应用程序保留在同一个 Java 服务器上被认为是不好的做法(根据微服务架构)。因此,只需将此类线程池视为遗留技术堆栈的一部分即可。
我正在开发 java 应用程序。我们正在使用 Spring 并且应用程序运行 WebSphere 应用程序服务器。在整个应用程序中,我们使用 Spring 维护在应用程序中创建的多个线程池。就像下面一样,到目前为止我们还没有遇到任何问题。
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="maxPoolSize" value="100"/>
<property name="corePoolSize" value="10"/>
</bean>
但我在阅读 Spring 框架参考文档时遇到了下面的段落,
34.3.3 TaskScheduler implementations
As with Spring’s TaskExecutor abstraction, the primary benefit of the TaskScheduler is that code relying on scheduling behavior need not be coupled to a particular scheduler implementation. The flexibility this provides is particularly relevant when running within Application Server environments where threads should not be created directly by the application itself. For such cases, Spring provides a TimerManagerTaskScheduler that delegates to a CommonJ TimerManager instance, typically configured with a JNDI-lookup.
ref. https://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html
所以我的问题是,如果我不关心访问 Java EE 上下文信息,还有哪些其他原因需要使用托管线程池? 我基本上想知道那里的最佳实践是什么,以及是否让应用程序管理线程是完全不可接受的。
通常,WebSphere 等企业服务器上的线程池(以及 JDBC 连接)不应由应用程序管理,而应由服务器本身管理。 Spring 仅提供您的应用程序和服务器线程池模型之间的接口。
在服务器端配置线程池的主要好处是效率:在过去,多个应用程序通常部署到同一台服务器上。使用共享线程池可以利用服务器的所有资源。如今,将多个应用程序保留在同一个 Java 服务器上被认为是不好的做法(根据微服务架构)。因此,只需将此类线程池视为遗留技术堆栈的一部分即可。