quartz-scheduler / quartz

Code for Quartz Scheduler
http://www.quartz-scheduler.org
Apache License 2.0
6.29k stars 1.94k forks source link

Don't start QuartzSchedulerThread in QuartzScheduler constructor #1083

Open ruanwenjun opened 11 months ago

ruanwenjun commented 11 months ago

Hi team,

Right now, I have two server, one is a web, and another is worker. The web server is used to CRUD Job and bind Trigger to Job, the worker server is used to execute the Job. Due to some reason, I cannot execute Job in portal server.

I use QuartzScheduler to CRUD Job and bind Trigger in web server, so I just initialize QuartzScheduler and don't execute the QuartzScheduler's start method.

I find quartz will start the QuartzSchedulerThread in QuartzScheduler's constructor. This seems not needed, if the QuartzScheduler doesn't start, the QuartzSchedulerThread seems only block in a loop

while (paused && !halted.get()) {
    try {
        // wait until togglePause(false) is called...
        sigLock.wait(1000L);
    } catch (InterruptedException ignore) {
    }

    // reset failure counter when paused, so that we don't
    // wait again after unpausing
    acquiresFailed = 0;
}
rohan-naik07 commented 10 months ago

@ruanwenjun can we add the schedThreadExecutor.execute(this.schedThread); line in the start method of the QuartzScheduler class?

ruanwenjun commented 10 months ago

@ruanwenjun can we add the schedThreadExecutor.execute(this.schedThread); line in the start method of the QuartzScheduler class?

LGTM, if we can move the execute method move to start.

jhouserizer commented 1 month ago

On initial cursory look, probably safe. I think (at least) past versions of the code relied upon the thread running even when used the way the poster describes - thus probably worth a closer look before any change is made.