SPRing配置文件:springmvc-servlet.xml中
xmlns加入
xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation中加入
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"spring掃描注解的配置:即掃描base-package包下所有注解
<context:component-scan base-package="com.imwoniu.*" />任務掃描注解
<task:executor id="executor" pool-size="5" /> <task:scheduler id="scheduler" pool-size="10" /> <task:annotation-driven executor="executor" scheduler="scheduler" />在實現中:/*每天16點38分執行一次這個方法。*/@Scheduled(cron = "0 38 16 * * ?") public void addAwardPool(){ GiftUtil.AWARD_POOL[0]=GiftUtil.AWARD_POOL[0]+10; GiftUtil.AWARD_POOL[1]=GiftUtil.AWARD_POOL[1]+50; GiftUtil.AWARD_POOL[2]=GiftUtil.AWARD_POOL[2]+30; GiftUtil.writeAwardMessageToFile(GiftUtil.AWARD_POOL,GiftUtil.AWARD_COUNT);//寫到文件 }
新聞熱點
疑難解答