介绍标签:lang,task,Spring,codesyntax,线程,taskExecutor From: https://blog.51cto.com/suren/5762911
本文介绍如何使用Spring中的线程池。
bean配置
[codesyntax lang="xml"]
<bean class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="40" />
<property name="keepAliveSeconds" value="600" />
</bean>
[/codesyntax]
示例
[codesyntax lang="java"]
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
/**
* 加入线程池执行任务
* @param task
*/
public void putThreadPool(Runnable task) {
taskExecutor.execute(task);
}
[/codesyntax]