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

Java tutorial

Introduction

Here is the source code for com.ling.spring.task.FixedRateTask.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.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

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

    /**
     * fixedRate ?
     * fixedDelay ??
     */
    @Async
    @Scheduled(fixedRate = 5000)
    public void runTask() {
        System.out.println("fixedRate run..." + format.format(new Date()));
        try {
            Thread.currentThread().sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String s = null;
        System.out.println(s.toString());
    }
}