Skip to content
pramode edited this page Jun 28, 2011 · 1 revision

Example - 1

Under the app folder, create a file called "Bootstrap.java":

   import play.jobs.*;

   @Every("3s")
   public class Bootstrap extends Job {
      public void doJob() {
        System.out.println("hello, job....");
      }   
   }

~
The function "doJob" gets called every 3 seconds!

Example - 2

Execute a function on application start:

      import play.jobs.*;
      import models.*;

      @OnApplicationStart
      public class Startup extends Job {
             public void doJob() {
             if(Client.count() == 0) {
                   Client c = new Client();
                   c.name = "foo";
                   c.age = 76; 
                   c.save();
             }   

      }   

This task will populate the database with one entry.

Clone this wiki locally