zoukankan      html  css  js  c++  java
  • 基于 Timer是一种定时器工具

    没有依赖   

    通过Timer中的schedule方法启动定时任务

    一般不采用此方法
    /**
     * -------------------------------------------------------------*
     *                     COPYRIGHT(C) 2018                        *
     *   National Audit Office of the People’s Republic Of China    *
     *                                                              *
     *                                                              *
     *  This work contains confidential business information        *
     *  and intellectual property of CNAO.                          *
     *  All rights reserved.                                        *
     * -------------------------------------------------------------*
     */
    /****************************************************************
     * Revision information:
     *
     *@version    1.0    2019年4月3日    Initial release (ChenJunMa)
     *
     ***************************************************************/
    package tt.tt;
    
    import org.springframework.stereotype.Service;
    
    
    import java.util.Timer;
    import java.util.TimerTask;
    
    
    /**
     *Timer是一种定时器工具,用来在一个后台线程计划执行指定任务。它可以计划执行一个任务一次或反复多次。
     * TimerTask一个抽象类,它的子类代表一个可以被Timer计划的任务。具体的任务在TimerTask中run接口中实现。
     * 通过Timer中的schedule方法启动定时任务。
     * ---------------------
     *
     *
     */
    @Service
    public class TimersDemo {
    
        private static Timer timer = new Timer();
    
        public TimersDemo() {
            TaskDemo task = new TaskDemo();
            timer.scheduleAtFixedRate(task, 10 * 1000, 10 * 1000);
            System.err.println("开始计时啦 宅男们 ...");
        }
    
        private class TaskDemo extends TimerTask {
    
            @Override
            public void run() {
                //开始调度啦
                System.err.println("你是笨笨猪呀--笨笨猪呀--笨笨猪呀--笨笨猪呀");
                System.out.println(getName("jb"));
    
            }
    
            private String getName(String str){
                return "毛毛哥 皮皮哥 宝强哥";
            }
    
        }
    
    
    }
    View Code
  • 相关阅读:
    explain详解与索引最佳实践
    MySQL的配置文件
    MySQL索引数据结构红黑树,Hash,B+树详解
    elasticsearch 进阶
    淘宝服务端高并发分布式架构演进之路
    http请求的header的一个小细节
    一次解决idea maven settings.xml文件不生效
    SpringBoot dev-tools vjtools dozer热启动类加载器不相同问题
    spring boot eclipse 远程调试
    vscode 同步配置
  • 原文地址:https://www.cnblogs.com/JonaLin/p/11250613.html
Copyright © 2011-2022 走看看