spring有对quartz的注解支持。实现定时器的功能
也可参照以下两种代码:
http://www.zuidaima.com/share/1586950010391552.htm
http://www.zuidaima.com/share/1550463459560448.htm
package com.zuidaima.quartz;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class TestJob {
@Scheduled(cron = "0/2 * * * * *")
public void process() {
System.out.println("job run");
}
public static void main(String[] args) throws InterruptedException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"applicationContext.xml");
while (true) {
System.out.println("main running...");
Thread.sleep(10000);
}
}
}
转载请注明出处: 分享通过spring注解实现的quartz job