The best way to differentiate between the two is that the timer's revelation time is set to a past time T,scheduleatfixedrate will execute all the tasks from T to now, and schedule will only be timed and executed from now on.
public class Hellomain { private static int count = 0; public static void Main (string[] args) { date date = new Date (System.currenttimemillis ()-n); Timer timer = new timer (); SYSTEM.OUT.PRINTLN ("Timer schedule before"); Timer.scheduleatfixedrate (New TimerTask () { @Override public void Run () { count++; SYSTEM.OUT.PRINTLN (count + "Timer task Run" + calendar.getinstance (). GetTime ()); } , date, +); SYSTEM.OUT.PRINTLN ("Timer schedule after"); try { Thread.Sleep (6000); } catch (Interruptedexception e) { e.printstacktrace (); } SYSTEM.OUT.PRINTLN ("Timer cancel before"); Timer.cancel (); SYSTEM.OUT.PRINTLN ("timer cancel after");} }
Schedule vs Scheduleatfixedrate