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>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。