當我們用到多個定時器的時候,有些定時器可能執行時間特別長,比如兩三個小時。如果對其他定時器,尤其是按頻率執行的定時器的精確率要求較高的時候,肯定就會出問題了。
這時候我們就需要用到多線程的定時器,其實很簡單,因爲定時器默認線程爲單線程,所以我們修改一下它的線程個數上限就行了,具體就是在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" /> <!-- 配置任務線程池 (這裏配置線程個數)--> <task:scheduler id="myScheduler" pool-size="5" /> </beans>