Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz vs. ScheduledExecutorService in Java web application

For a system monitoring Java application which currently runs on the command line and uses ScheduledExecutorService, I would like to write a simple web application version, to be run in a Servlet container like Apache Tomcat or Eclipse Jetty.

I have read about Quartz as one of the popular job schedulers for web applications. Would it be better (maybe because of better servlet container integration) to port this application from ScheduledExecutorService to Quartz?

Adding another library dependency to the application is not a problem, I am interested in technical reasons against usage of ScheduledExecutorService.

like image 870
mjn Avatar asked Jan 18 '11 15:01

mjn


People also ask

What is ScheduledExecutorService in Java?

public interface ScheduledExecutorService extends ExecutorService. An ExecutorService that can schedule commands to run after a given delay, or to execute periodically. The schedule methods create tasks with various delays and return a task object that can be used to cancel or check execution.

Does spring scheduler use quartz?

27.6 Using the Quartz Scheduler For convenience purposes, Spring offers a couple of classes that simplify the usage of Quartz within Spring-based applications.

Why is quartz A scheduler?

Quartz scheduler allows an enterprise to schedule a job at a specified date and time. It allows us to perform the operations to schedule or unschedule the jobs. It provides operations to start or stop or pause the scheduler. It also provides reminder services.


1 Answers

It depends on what you are using it for.

Quartz is useful for programmed times e.g. every hour on the hour.

ScheduledExecutorService is useful for repeating tasks which don't have to occur at a specific time. Its simpler and possibly more efficient. If you have this working it indicates to me that you don't need Quartz.

like image 101
Peter Lawrey Avatar answered Oct 02 '22 18:10

Peter Lawrey