The easiest way is to use the provided task tags in your spring configuration. Note the task namespace below
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:ctx="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd ">
as soon as you do this you can use
<task:scheduler id="taskScheduler" pool-size="4"/> <task:scheduled-tasks scheduler="taskScheduler"> <task:scheduled ref="someBean" method="someMethod" fixed-rate="21600000" initial-delay="60000"/> </task:scheduled-tasks>
etc .. your current scheduled task is a bean with a method that is being called. You can schedule it with a fixed delay or on cron, etc.
you can also declare artists in config as follows:
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <description>A task pool for general use</description> <property name="corePoolSize" value="150" /> <property name="maxPoolSize" value="200" /> <property name="queueCapacity" value="10" /> <property name="keepAliveSeconds" value="0"/> <property name="waitForTasksToCompleteOnShutdown" value="false"/> </bean>
You can use an executor to perform a pool of parallel tasks (enter a bean in your bean and see what it provides).
source share