Android Task Scheduler (Timer, cron4j)

Source: Internet
Author: User

The time-Dispatch module was used in the recent project development, and Quartz.net was used in. NET development, and then downloaded the Java Quartz module, but it appeared in use java.lang.NoClassDefFoundError Anomalies, and later on-line search found alternative methods

Using the system comes with the timer code as follows:

 Public class extends timertask{    @Override    publicvoid  run () {        System.out.println ( New Date ());}    }
SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Timer Timer=NewTimer (); Try{timer.schedule (NewJavatask (), Sdf.parse ("2015-03-12 11:47:00")); Timer.schedule (NewJavatask (), Sdf.parse ("2015-03-12 11:18:00")); Timer.schedule (NewJavatask (), Sdf.parse ("2015-03-12 11:19:00")); }Catch(ParseException e) {e.printstacktrace (); }        Try{Thread.Sleep (80000); }        Catch(Interruptedexception e) {} timer.cancel ();

Using a third-party class cron4j

 public  class  mytask "implements   Runnable {@Override  public< /span> void   run () {System.out.println ("        Current system time: "+ new   Date ());    System.out.println ( another minute ticked away ... "); }}
New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");         New MyTask ();         New Scheduler ();        Scheduler.schedule ("5 * * * *", Task);        Scheduler.start ();         Try {            Thread.Sleep (5L * 60L * 1000L);         Catch (interruptedexception e) {            ;        }        Scheduler.stop ();

Record, easy to use later!

  

Android Task Scheduler (Timer, cron4j)

Related Article

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.