zoukankan      html  css  js  c++  java
  • java 定时器

       //时间间隔(一天)   

        private static final long PERIOD_DAY = 24 * 60 * 60 * 1000;   

        public void executeTask(){ 

            Timer timer = new Timer(); 

            Calendar calendar = Calendar.getInstance(); 

            int year = calendar.get(Calendar.YEAR); 

            int month = calendar.get(Calendar.MONTH); 

            int day = calendar.get(Calendar.DAY_OF_MONTH);// 每天 

            // 定制每天的03:30:00执行, 

            calendar.set(year, month, day, 03, 30, 00); 

            Date date = calendar.getTime(); 

            if (date.before(new Date())) {   

                date = this.addDay(date, 1);   

            }  

            timer.schedule(new MyTask(), date, PERIOD_DAY); 

        } 

        static class MyTask extends java.util.TimerTask { 

            @Override 

            public void run() { 

                System.out.println("----Start execute my task------");      

            } 

        } 

  • 相关阅读:
    leetcode 78. 子集 JAVA
    leetcode 91. 解码方法 JAVA
    leetcode 75. 颜色分类 JAVA
    leetcode 74 搜索二维矩阵 java
    leetcode 84. 柱状图中最大的矩形 JAVA
    last occurance
    first occurance
    classical binary search
    LC.234.Palindrome Linked List
    LC.142. Linked List Cycle II
  • 原文地址:https://www.cnblogs.com/wale/p/4350796.html
Copyright © 2011-2022 走看看