zoukankan      html  css  js  c++  java
  • SpringBoot定时任务(Spring Schedule )实现方法

    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()));
          }
    
    }
  • 相关阅读:
    瀑布流
    轮播图
    封装动画的函数
    回到顶部带动画
    动画setInterval
    模拟滚动条
    放大镜
    刷新
    cookie
    拖拽
  • 原文地址:https://www.cnblogs.com/shihaiming/p/7814637.html
Copyright © 2011-2022 走看看