當(dāng)我們用到多個定時器的時候,有些定時器可能執(zhí)行時間特別長,比如兩三個小時。如果對其他定時器,尤其是按頻率執(zhí)行的定時器的精確率要求較高的時候,肯定就會出問題了。
這時候我們就需要用到多線程的定時器,其實(shí)很簡單,因為定時器默認(rèn)線程為單線程,所以我們修改一下它的線程個數(shù)上限就行了,具體就是在XML里面加幾個配置,今天花了一天來解決這個問題,避免以后再遇到,所以記錄以下~~~~
以下為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:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
classpath:/org/springframework/beans/factory/xml/spring-beans-4.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.1.xsd">
<!-- 啟用annotation方式 -->
<task:annotation-driven scheduler="myScheduler" />
<!-- 配置任務(wù)線程池 (這里配置線程個數(shù))-->
<task:scheduler id="myScheduler" pool-size="5" />
</beans>

浙公網(wǎng)安備 33010602011771號