List of usage examples for java.util Timer scheduleAtFixedRate
public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)
From source file:Main.java
public static void main(String[] args) { TimerTask task = new Main(); Timer timer = new Timer(); timer.scheduleAtFixedRate(task, new Date(), 1000); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int delay = 5000; // delay for 5 sec. int period = 1000; // repeat every sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { System.out.println("doing"); }//from ww w. ja v a 2 s .c o m }, delay, period); }
From source file:MyTimerTask.java
public static void main(String[] args) { TimerTask tasknew = new MyTimerTask(); Timer timer = new Timer(); timer.scheduleAtFixedRate(tasknew, 500, 1000); }
From source file:MyTimerTask.java
public static void main(String[] args) { TimerTask tasknew = new MyTimerTask(); Timer timer = new Timer(); timer.scheduleAtFixedRate(tasknew, new Date(), 1000); }
From source file:Main.java
public static void main(String... arguments) { TimerTask fetchMail = new Main(); // perform the task once a day at 4 a.m., starting tomorrow morning Timer timer = new Timer(); timer.scheduleAtFixedRate(fetchMail, getTomorrowMorning4am(), fONCE_PER_DAY); }
From source file:MyTimerTask.java
public static void main(String[] args) { // creating timer task, timer TimerTask task = new MyTimerTask(); Timer timer = new Timer(); // scheduling the task timer.scheduleAtFixedRate(task, new Date(), 1000); }
From source file:MyTimerTask.java
public static void main(String[] args) { // creating timer task, timer TimerTask task = new MyTimerTask(); Timer timer = new Timer(); // scheduling the task timer.scheduleAtFixedRate(task, new Date(), 1000); // checking scheduled execution time System.out.println("Time is :" + task.scheduledExecutionTime()); }
From source file:MyTimerTask.java
public static void main(String[] args) { TimerTask task = new MyTimerTask(); Timer timer = new Timer(); // scheduling the task timer.scheduleAtFixedRate(task, new Date(), 1000); // cancelling the task System.out.println("cancelling task: " + task.cancel()); }
From source file:MyTimerTask.java
public static void main(String[] args) { // creating timer task, timer TimerTask tasknew = new MyTimerTask(); Timer timer = new Timer(); // scheduling the task timer.scheduleAtFixedRate(tasknew, new Date(), 10); // cancel task timer.cancel();// w ww.ja v a2 s . co m // purging the timer System.out.println("purge value :" + timer.purge()); }
From source file:org.apache.hadoop.chukwa.inputtools.jplugin.JPluginAgent.java
@SuppressWarnings("unchecked") public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java -DPERIOD=nn JavaPluginAgent <class name> [parameters]"); System.exit(0);//from www .j a va 2 s . c o m } int period = -1; try { if (System.getProperty("PERIOD") != null) { period = Integer.parseInt(System.getProperty("PERIOD")); } } catch (NumberFormatException ex) { ex.printStackTrace(); System.out.println("PERIOD should be numeric format of seconds."); System.exit(0); } JPlugin plugin = null; try { plugin = (JPlugin) Class.forName(args[0]).newInstance(); plugin.init(args); } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } try { DaemonWatcher.createInstance(plugin.getRecordType() + "-data-loader"); } catch (Exception e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); long now = cal.getTime().getTime(); cal.set(Calendar.SECOND, 3); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.MINUTE, 1); long until = cal.getTime().getTime(); try { if (period == -1) { new MetricsTimerTask(plugin).run(); } else { Thread.sleep(until - now); Timer timer = new Timer(); timer.scheduleAtFixedRate(new MetricsTimerTask(plugin), 0, period * 1000); } } catch (Exception ex) { } }