Package it.sauronsoftware.cron4j

Examples of it.sauronsoftware.cron4j.Scheduler


  public static void main(String[] args) {
    // Prepares the task.
    MyTask task = new MyTask();
    // Creates the scheduler.
    Scheduler scheduler = new Scheduler();
    // 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();
  }
View Full Code Here


  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    // Retrieves the servlet context.
    ServletContext context = getServletContext();
    // Retrieves the scheduler.
    Scheduler scheduler = (Scheduler) context
        .getAttribute(Constants.SCHEDULER);
    // Retrieves the executors.
    TaskExecutor[] executors = scheduler.getExecutingTasks();
    // Registers the executors in the request.
    req.setAttribute("executors", executors);
    // Action requested?
    String action = req.getParameter("action");
    if ("pause".equals(action)) {
View Full Code Here

    // 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();
  }
View Full Code Here

  public static void main(String[] args) {
    // Declares the file.
    File file = new File("cron4jtab.txt");
    // Creates the scheduler.
    Scheduler scheduler = new Scheduler();
    // Schedules the file.
    scheduler.scheduleFile(file);
    // Starts the scheduler.
    scheduler.start();
    // Stays alive for five minutes.
    try {
      Thread.sleep(5L * 60L * 1000L);
    } catch (InterruptedException e) {
      ;
    }
    // Stops the scheduler.
    scheduler.stop();
  }
View Full Code Here

public class SchedulerServletContextListener implements ServletContextListener {

  public void contextInitialized(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    // 1. Creates the scheduler.
    Scheduler scheduler = new Scheduler();
    // 2. Registers a custom task collector.
    TaskCollector collector = new MyTaskCollector();
    scheduler.addTaskCollector(collector);
    // 3. Starts the scheduler.
    scheduler.start();
    // 4. Registers the scheduler.
    context.setAttribute(Constants.SCHEDULER, scheduler);
  }
View Full Code Here

  }

  public void contextDestroyed(ServletContextEvent event) {
    ServletContext context = event.getServletContext();
    // 1. Retrieves the scheduler from the context.
    Scheduler scheduler = (Scheduler) context.getAttribute(Constants.SCHEDULER);
    // 2. Removes the scheduler from the context.
    context.removeAttribute(Constants.SCHEDULER);
    // 3. Stops the scheduler.
    scheduler.stop();
  }
View Full Code Here

      error("Database error: " + e1.getMessage());
      error("This is a critical error. Terminating.");
      System.exit(1);
    }
   
    cleanerScheduler = new Scheduler();
   
    cleanerThread = new Thread(new Cleaner());
   
    cleanerScheduler.schedule(Npvrd.config.cleanerSchedule, cleanerThread);
    cleanerScheduler.start();
View Full Code Here

  static Configuration config;
  static volatile Scheduler scheduler;
 
  public static void main(String[] args) {
    String configFile = "config.xml";
    scheduler = new Scheduler();
   
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-c")) {
        configFile = args[++i];
      }
View Full Code Here

        return this;
    }
   
    @Override
    public boolean start() {
        scheduler = new Scheduler();
        loadJobsFromProperties();
        Set<Entry<String, Runnable>> set = jobs.entrySet();
        for (Entry<String, Runnable> entry : set) {
            scheduler.schedule(entry.getKey(), entry.getValue());
            log.debug(entry.getValue() + " has been scheduled to run and repeat based on expression: " + entry.getKey());
View Full Code Here

    public void setCronSheduller(String cronString) {
        try {
            if (scheduler != null) {
                scheduler.stop();
            }
            scheduler = new Scheduler();
            scheduler.schedule(cronString, new RefreshIndexThread());
            if (!scheduler.isStarted()) {
                scheduler.start();
            }
        } catch (IllegalStateException | InvalidPatternException e) {
View Full Code Here

TOP

Related Classes of it.sauronsoftware.cron4j.Scheduler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.