Spring: Disable Quartz Worker in some of the pods in clustered mode via configuration

66 views Asked by At

I have a service which uses Quartz scheduler, its deployed in kubernetes in clustered mode.

I need all the instances to be able to create tasks to the quartz, but only some of them to be act as workers to run the job and remaining just for managing the jobs (managers). Managers should be able to add tasks but the jobs should not run on them. The code deployed on both of them are same, only changes should be on the configurations.

I tried this

public class QuartzSchedulerFactoryBean extends SchedulerFactoryBean {

    @Autowired
    AppConfiguration configuration;

    @Override
    public void afterPropertiesSet() throws Exception {
        if(configuration.getQuartzWorkerEnabled())
            super.afterPropertiesSet();
    }
}

But this will disable the scheduler also, so that I cannot add tasks to the quartz.

I tried setting threadCount to 0 but that will give error starting the quartz.

1

There are 1 answers

0
javaDeveloper On

Use a different configuration file for the manager and scheduler.

For manager use the ZeroSizeThreadpool

org.quartz.threadPool.class=org.quartz.simpl.ZeroSizeThreadPool

Sometimes this may throw an error no setter found for threadCount

In that case define a custom threadpool extending ZeroSizeThreadPool

import org.quartz.simpl.ZeroSizeThreadPool;

public class CustomZeroSizeThreadPool extends ZeroSizeThreadPool {
    public void setThreadCount(int count) {
        // do Nothing
    }

    @Override
    public int blockForAvailableThreads() {
        return 0;
    }
}