Home  >  Article  >  Web Front-end  >  How to use spring boot’s scheduled tasks

How to use spring boot’s scheduled tasks

php中世界最好的语言
php中世界最好的语言Original
2018-03-14 13:11:591427browse

This time I will show you how to use the scheduled tasks of spring boot. What should be precautions when using the scheduled tasks of spring boot. The following is a practical case, let's take a look.

@Componentpublic class GetIndexInfo {    public final static long ONE_Minute =  60 * 1000;    /*当任务执行完毕后1分钟在执行*/
    @Scheduled(fixedDelay=ONE_Minute)    public void fixedDelayJob(){
        System.out.println("---------------1-----------------");
        System.out.println(new Date().getTime());
    }    /*每多次分钟一次*/
    @Scheduled(fixedRate=ONE_Minute)    public void fixedRateJob(){
        System.out.println("---------------2-----------------");
        System.out.println(new Date().getTime());
    }    /*每周日凌晨三点执行*/
    @Scheduled(cron="0 10 3 ? * 1")    public void cronJob(){
        System.out.println("---------------3-----------------");
        System.out.println(new Date().getTime());
    }    synchronized static void writeFile(String filePath, JSONObject json) {        try {
            FileWriter fw = new FileWriter(filePath, false);
            PrintWriter out = new PrintWriter(fw);
            out.write(json.toString());
            out.println();
            fw.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

javaScript uses call and apply

##The process of using http protocol

Detailed explanation of javaScript objects

css3 achieves strip percentage effect

The above is the detailed content of How to use spring boot’s scheduled tasks. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn