Basic Schduler in spring 3
<beans
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
">
<task:scheduler id="Scheduler" pool-size="10" />
<task:executor id="TaskExecutor" pool-size="10"/>
<task:annotation-driven executor="TaskExecutor" scheduler="Scheduler"/>
<bean id="schedulerService" class="com.operation.service.SchedulerService"
scope="singleton"/>
/**
* @author jjhangu
*
*/
public class SchedulerService {
@Scheduled(fixedDelay = 5000)
public void doSomething() {
final long time = System.currentTimeMillis();
final SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
final String str = dayTime.format(new Date(time));
System.out.println("gap is 5 second" + str);
}
}
log gap is 5scond2013-06-28 02:06:44
log gap is 5scond2013-06-28 02:06:49
No comments:
Post a Comment