コード例 #1
0
  /** Activates the policy. Schedules acquire/release tasks with specified period. */
  @Override
  public BooleanWrapper activate() {
    cronScheduler.schedule(
        nodeAcquision,
        new Runnable() {
          public void run() {
            logger.info("Acquiring nodes");
            thisStub.acquireAllNodes();
          }
        });
    cronScheduler.schedule(
        nodeRemoval,
        new Runnable() {
          public void run() {
            logger.info("Removing nodes");
            thisStub.removeAllNodes(preemptive);
          }
        });
    cronScheduler.start();

    if (forceDeployment) {
      logger.info("Acquiring nodes");
      thisStub.acquireAllNodes();
    }
    return new BooleanWrapper(true);
  }
コード例 #2
0
ファイル: Main.java プロジェクト: 0312birdzhang/cron4j
 public static void main(String[] args) {
   // Prepares the listener.
   MySchedulerListener listener = new MySchedulerListener();
   // Prepares the task.
   MyTask task = new MyTask();
   // Creates the scheduler.
   Scheduler scheduler = new Scheduler();
   // Registers the listener.
   scheduler.addSchedulerListener(listener);
   // Schedules the task, once every minute.
   scheduler.schedule("* * * * *", task);
   // Starts the scheduler.
   scheduler.start();
   // Stays alive for five minutes.
   try {
     Thread.sleep(5L * 60L * 1000L);
   } catch (InterruptedException e) {;
   }
   // Stops the scheduler.
   scheduler.stop();
 }