com.ling.spring.task.FixedDelayTask.java Source code

Java tutorial

Introduction

Here is the source code for com.ling.spring.task.FixedDelayTask.java

Source

/*
 * Copyright 2005-2020 Daxia Team All rights reserved.
 * Support: zhangzhen
 * License: Daxia Team license
 */
package com.ling.spring.task;

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

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class FixedDelayTask {
    static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Scheduled(fixedDelay = 5000)
    public void runTask() {

        System.out.println("fixedDelay run..." + format.format(new Date()));
        try {
            Thread.currentThread().sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}