Java Reset Timer frequency

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.