Spring异步

来源:互联网 发布:反兴奋剂大数据 编辑:程序博客网 时间:2024/06/05 10:31

SpringMVC中:

 <!--异步线程执行器,用于异步发送-->
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="3"/>
<property name="maxPoolSize" value="10"/>
</bean>

程序中:

@Resource
TaskExecutor taskExecutor;//注入Spring封装的异步执行器

写法:

taskExecutor.execute(new Runnable(){
public void run(){
  try {
 内容
   } catch (Exception e) {
    log.error(e.getMessage());
   }
}
});



0 0