作者:手机用户2502934681 | 来源:互联网 | 2023-10-12 09:34
FastDateFormatfdfFastDateFormat.getInstance("yyyy-MM-ddHH:mm:ss&qu
FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
fdf.format(new Date())
import java.util.Date;
import org.apache.commons.lang3.time.FastDateFormat;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.dudu.constant.Constant;
@Component
public class ScheduleJobs {
public final static long SECOnD= 1 * 1000;
FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
/**
* 固定等待时间 @Scheduled(fixedDelay = 时间间隔 )
* @throws InterruptedException
*/
@Scheduled(fixedDelay = SECOND * 2)
public void fixedDelayJob() throws InterruptedException {
Constant.LOGGER.info("[FixedDelayJob Execute]"+fdf.format(new Date()));
}
/**
* 固定间隔时间 @Scheduled(fixedRate = 时间间隔 )
*/
@Scheduled(fixedRate = SECOND * 4)
public void fixedRateJob() {
Constant.LOGGER.info("[FixedRateJob Execute]"+fdf.format(new Date()));
}
/**
* Corn表达式 @Scheduled(cron = Corn表达式)
*/
@Scheduled(cron = "0/4 * * * * ?")
public void cronJob() {
Constant.LOGGER.info("[CronJob Execute]"+fdf.format(new Date()));
}
}