隨筆-48  評論-26  文章-0  trackbacks-0
          package com.timer.test;

          import java.util.Calendar;
          import java.util.Date;
          import java.util.Timer;
          import java.util.TimerTask;

          /****
           * TimerTask與Timer
           * 
           * 
          @author bruceleey
           * 
           
          */
          public class TestTimer {
              
          static int count = 0;

              
          public static void showTimer() {
                  TimerTask task 
          = new TimerTask() {
                      @Override
                      
          public void run() {
                          
          ++count;
                          System.out.println(
          "count執行了-->" + count); // 1次
                      }

                  };

                  Calendar calendar 
          = Calendar.getInstance();
                  
          int year = calendar.get(Calendar.YEAR);
                  
          int month = calendar.get(Calendar.MONTH)+1;
                  
          int day = calendar.get(Calendar.DAY_OF_MONTH);
                  
          /*** 定制每日00:24:00執行方法 ***/
                  calendar.set(year, month, day, 
          242400);
                  Date date 
          = calendar.getTime();
                  Timer timer 
          = new Timer();
                  timer.schedule(task, date);
              }

              
          public static void main(String[] args) {
                  showTimer();
              }

          }
          posted on 2009-09-26 14:28 Worker 閱讀(2615) 評論(1)  編輯  收藏 所屬分類: J2SE/J2EE

          評論:
          # re: Java Timer定制每天特定時間執行任務 2014-09-01 17:27 | 夢飛
          這個可行嗎?  回復  更多評論
            
          <2009年9月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          常用鏈接

          留言簿(1)

          我參與的團隊

          隨筆分類(47)

          隨筆檔案(48)

          Forum

          Fun

          Study

          Util

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜


          主站蜘蛛池模板: 武川县| 七台河市| 红安县| 昔阳县| 岳普湖县| 蒲城县| 青浦区| 汉中市| 西藏| 西丰县| 壤塘县| 崇文区| 福贡县| 方城县| 垦利县| 开化县| 崇礼县| 晴隆县| 同德县| 化州市| 黎川县| 探索| 拉萨市| 万州区| 淮阳县| 图片| 阿合奇县| 商河县| 林芝县| 曲沃县| 文登市| 云龙县| 苍南县| 齐河县| 林周县| 天气| 杭锦后旗| 尤溪县| 襄城县| 远安县| 余江县|