• Java定时器Timer


    public class TimerTest {
        //第一种方法:设定指定任务task在指定时间time后执行
        //schedule(timertask,Date time)
        public static void timer1(){
            Timer timer = new Timer();
            timer.schedule(new TimerTask(){
                public void run(){
                    System.out.println("-------timer1 test -----");
                }
            }, 5000);
        }
        //第二种方法:设定指定任务task在指定延迟delay后进行固定延迟period周期的进行
        //schedule(TimerTask task, long delay, long period)
        public static void timer2(){
            Timer timer = new Timer();
            timer.schedule(new TimerTask(){
                public void run(){
                    System.out.println("-------timer2 test -----");
                }
            }, 1000,5000);
        }
        //第三种方法第三种方法:设定指定任务task在指定延迟delay后进行固定频率peroid的执行。
        //scheduleAtFixedRate(TimerTask task, long delay, long period)
        public static void timer3(){
            Timer timer = new Timer();
            timer.scheduleAtFixedRate(new TimerTask(){
                public void run(){
                    System.out.println("-------timer3 test -----");
                }
            }, 1000,5000);
        }
        //第四种方法:安排指定的任务task在指定的时间firstTime开始进行重复的固定速率period执行.
        // Timer.scheduleAtFixedRate(TimerTask task,Date firstTime,long period)
        public static void timer4(){
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR, 14);
            calendar.set(Calendar.MINUTE,30);
            calendar.set(Calendar.SECOND,00);
            Date time = calendar.getTime();
            Timer timer = new Timer();
            timer.scheduleAtFixedRate(new TimerTask(){
                public void run(){
                    System.out.println("-------timer4 test -----");
                }
            },time,1000*60*60*24);
        }
        
        public static void main(String []args){
            timer1();
            timer4();
        }
    }
  • 相关阅读:
    jQuery之.on()方法
    18款 非常实用 jquery幻灯片图片切换
    jquery 处理字符串
    JS中document.createElement()用法及注意事项
    jquery 创建 SVG DOM 的处理方法
    jQuery append xmlNode 修改 xml 内容
    jQuery与XML
    浏览器中的XML与JavaScript
    DOM(文本对象模型)简介
    用jQuery 处理XML-- jQuery与XML
  • 原文地址:https://www.cnblogs.com/heyjia/p/11225672.html
Copyright © 2020-2023  润新知