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()));
      }

}

 

相关文章:

  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
猜你喜欢
  • 2023-03-22
  • 2021-06-17
  • 2022-12-23
  • 2021-11-29
  • 2021-05-17
  • 2022-12-23
相关资源
相似解决方案