温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringMVC定时任务(task)开启多线程执行

发布时间:2020-07-17 17:06:32 来源:网络 阅读:1788 作者:pannijingling 栏目:编程语言

  spring的task默认是单线程执行,如果定时任务过多,某个任务执行时间过长,就可能影响到其他任务的执行频率,因此,有必要给其添加多线程并行执行,可以有效降低任务被影响的几率。解决方案就是修改xml文件配置,代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task" 

    xsi:schemaLocation="     
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/task
          http://www.springframework.org/schema/task/spring-task.xsd"
          default-autowire="byName" default-lazy-init="false">

    <!-- 1.扫描指定的包 -->
    <context:component-scan base-package="com.qfx.system.task"/>

    <!-- 2.启用定时任务 -->
    <!-- <task:annotation-driven /> -->
    <task:annotation-driven scheduler="myTask" />

    <!-- 3.配置定时任务的线程池 -->
    <task:scheduler id="myTask" pool-size="5"/>
</beans>
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI