Question

Can anyone tell,advice how to run a scheduler without Quartz in java. I want to implement such features that if application server remain stop , my scheduler will run. So I thought the executable class to place outside of the war file. So can anyone give me suggestion ? Thanks.

Was it helpful?

Solution

Regarding scheduling tasks without Quartz, you can use Java's ScheduledExecutorService:

ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

final Runnable beeper = new Runnable() {
    public void run() { System.out.println("beep"); }
};

// Beeps every 10 seconds
scheduler.scheduleAtFixedRate(beeper, 0, 10, TimeUnit.SECONDS);

Now, regarding doing it when your application is not running, I see three options:

  • Develop a stand-alone application with your scheduled tasks, decoupled from your webapp
  • Look up for Application Server features for that purpose
  • OS scheduled tasks, as Linux's cron job
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top