Springでタスクのスケジューラを実現する(Spring @Scheduled)方法

1.xmlの設定に次の内容を追記
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd"

2.javaコード:
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Lazy(false)
public class TestJob {
public static SimpleDateFormat sdf_yyyyMMddHHmmss = new SimpleDateFormat(“yyyyMMddHHmmss");

@Scheduled(cron = “0/10 * * * * ?")
public void exejob() {
System.out.println(sdf_yyyyMMddHHmmss.format(new Date()) + " :動いている");
}
}

 

Java

Posted by arkgame