Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Scheduler tasks should be placed only in Global class. Create two tasks, schedule only once first with <code>initialDelay</code> = 0 milliseconds.</p> <p>For the second task, you need to calculate seconds between current DateTime and next planned occurrence (ie. tomorrow at 8:00 o'clock) using common date/time classes, then set this difference as <code>initialDelay</code> and also set <code>frequency</code> to 24 hours.</p> <p>In result, it will start at the application start and will schedule the task for execution each day at required hour.</p> <p><strong>Edit</strong></p> <p>There's complete sample, (save/edit the class: <code>/app/Global.java</code>):</p> <pre><code>import akka.util.Duration; import org.joda.time.DateTime; import org.joda.time.Seconds; import play.Application; import play.GlobalSettings; import play.Logger; import play.libs.Akka; import java.util.concurrent.TimeUnit; public class Global extends GlobalSettings { @Override public void onStart(Application application) { Akka.system().scheduler().scheduleOnce( Duration.create(0, TimeUnit.MILLISECONDS), new Runnable() { @Override public void run() { Logger.info("ON START --- " + System.currentTimeMillis()); } } ); Akka.system().scheduler().schedule( Duration.create(nextExecutionInSeconds(8, 0), TimeUnit.SECONDS), Duration.create(24, TimeUnit.HOURS), new Runnable() { @Override public void run() { Logger.info("EVERY DAY AT 8:00 --- " + System.currentTimeMillis()); } } ); } public static int nextExecutionInSeconds(int hour, int minute){ return Seconds.secondsBetween( new DateTime(), nextExecution(hour, minute) ).getSeconds(); } public static DateTime nextExecution(int hour, int minute){ DateTime next = new DateTime() .withHourOfDay(hour) .withMinuteOfHour(minute) .withSecondOfMinute(0) .withMillisOfSecond(0); return (next.isBeforeNow()) ? next.plusHours(24) : next; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload