您的位置:首页 > 编程语言 > Java开发

spring线程池ThreadPoolTaskExecutor应用

2017-12-13 16:44 351 查看
1、线程池配置文件

#一般采用properties配置

threadpool.corePoolSize=20

threadpool.maxPoolSize=50

threadpool.queueCapacity=20000

2、spring配置文件

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="${threadpool.corePoolSize}" />
<property name="maxPoolSize" value="${threadpool.maxPoolSize}" />
<property name="queueCapacity" value="${threadpool.queueCapacity}" />
<property name="threadNamePrefix" value="resume_" />
</bean>


3、java代码中注入线程池

@Autowired
private ThreadPoolTaskExecutor taskExecutor;


启线程:

taskExecutor.execute(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub

}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息