Please consider this example.
A sample web application calls scheduler.start()
on its start up. The scheduler configured to store its jobs in DB.
The application is copied on six web-servers.
So if we start six web-servers we will have six scheduler with same name on a single DB. As mentioned in https://quartz-scheduler.org/documentation/quartz-2.1.x/cookbook/MultipleSchedulers:
Never start (scheduler.start()) a non-clustered instance against the same set of database tables that any other instance with the same scheduler name is running (start()ed) against. You may get serious data corruption, and will definitely experience erratic behavior.
So this will fail.
My question is that if I am sure that all of my jobs have @DisallowConcurrentExecution
will above work or it will still fail ?!
If @DisallowConcurrentExecution
does not help, I should do it manually configure one server as some how Master
public class StartUp implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
if(THIS_IS_MASTER_TOMCAT){
scheduler.start()
}
}
Are there better ways?!
Best Answer
Basically Rene M. is correct. Here are the docs in question vis-a-vis Quartz:
http://www.quartz-scheduler.org/documentation/quartz-2.2.x/configuration/ConfigJDBCJobStoreClustering.html
Now some background and a conceptual example from our own use at my company. We use quartz clustering mode within a Wildfly Cluster. That is each wildfly cluster node runs quartz. Since quartz is running in cluster mode itself and is pointed at the same database schema we are guaranteed to run one job per cluster. Again, see the documentation. The key issues are this:
schema. You obviously must create the relational database tables per the documentation. No biggie.
quartz.property example:
Now our datasource snippet within standalone.xml:
You fill in the rest of this datasource element per your requirements. The @DisallowConcurrentExecution is a good idea to prevent multiple jobs on a single node form executing a particular method but it is the quartz clustering that prevents the same job running on multiple VM's; not this annotation.