1 Public classBallutil {2 Public StaticTimer Fistimer;3 4 Public Static voidFisstartball () {5 LongFirsttime = 2000l;6 LongTime = 2000l;7 if(fistimer==NULL){8Fistimer =NewTimer ();9 }TenFistimer.scheduleatfixedrate (NewTimerTask () { One Public voidrun () { ASystem.out.println ("time=" +time+ "-----firsttime=" + "Timer Execution" + "----type=" +type); -Date Date =NewDate (); - inthour =date.gethours (); the if(hour==9){ -SYSTEM.OUT.PRINTLN ("Reset Frequency"); -Stop ();//turn it off before you turn it on - start (); + //update the new time directly - //Long newtime = Patt.getint ("Intervday") *60l*1000; + //Resetperiod (newtime); A } at } - //This method can also reset the frequency, passing the new time directly - Public voidResetperiod (Final LongTimethrowsIllegalArgumentException, illegalaccessexception{ -field[] Fields = This. GetClass (). Getsuperclass (). Getdeclaredfields (); - for(Field field:fields) - { in if(Field.getname (). EndsWith ("period")) - { to if(!field.isaccessible ()) + { -Field.setaccessible (true); the } *Field.set ( This, time); $ } Panax Notoginseng } - } the }, Firsttime, time); + } A Public Static voidstart () { the Fisstartball (); + } - $ Public Static voidStop () { $ Fistimer.cancel (); - } -}
Java Reset Timer frequency