標籤:type 方法 tin timertask with system name res start
1 public class BallUtil { 2 public static Timer fisTimer ; 3 4 public static void fisStartBall(){ 5 long firstTime = 2000l; 6 long time = 2000l; 7 if(fisTimer==null){ 8 fisTimer = new Timer(); 9 }10 fisTimer.scheduleAtFixedRate(new TimerTask(){11 public void run(){12 System.out.println("time="+time+"-----firstTime="+"定時器執行"+"----type="+type);13 Date date = new Date();14 int hour = date.getHours();15 if(hour==9){16 System.out.println("重設頻率");17 stop();//關閉後再開啟18 start();19 //直接更新新的時間20 //Long newTime = patt.getInt("INTERVDAY")*60l*1000;21 //resetPeriod(newTime);22 }23 }24 //此方法也可以重設頻率,直接傳入新的時間25 public void resetPeriod(final long time) throws IllegalArgumentException, IllegalAccessException{26 Field[] fields = this.getClass().getSuperclass() .getDeclaredFields(); 27 for (Field field : fields) 28 { 29 if (field.getName().endsWith("period")) 30 { 31 if (!field.isAccessible()) 32 { 33 field.setAccessible(true); 34 } 35 field.set(this, time); 36 } 37 } 38 }39 }, firstTime, time);40 }41 public static void start(){42 fisStartBall();43 }44 45 public static void stop(){46 fisTimer.cancel();47 }48 }
java重設定時器頻率