我希望能够将 ExecutorService 实例注入(inject)到我的 Spring 服务中,Spring API 建议为此目的使用 ThreadPoolExecutorFactoryBean。很简单的问题;我到底该如何使用 ThreadPoolExecutorFactoryBean 创建一个可以连接到其他服务的 ExecutorService?
问他的问题我觉得自己像个白痴,但我似乎无法弄清楚这个问题。
最佳答案
展开skaffman's answer ,这是一个简短而贴心的例子,说明需要做什么:
<bean id="classNeedingExecutor" class="foo.Bar">
<property name="executor" ref="threadExecutor" />
</bean>
<bean id="threadExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean">
<property name="corePoolSize" value="1" />
<property name="maxPoolSize" value="1" />
</bean>
再次,请参阅 JavaDocs有关可以设置以配置 ExecutorService 的其他属性的说明。
关于java - Spring ThreadPoolExecutor Factory Bean工厂bean的使用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6083466/