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)