Hi I'm new to Quartz Scheduler, i'm implementing it for the first time. I would like to know if the scheduler's start call will even execute the paused jobs? or Paused jobs will only be activated by resume call alone and nothing else. Please help me.
First of all, you can pause a trigger or scheduler, not a job. Do not be confused, that for example IScheduler interface has different pause methods, and one of them for example is PauseJobs(), they all affect triggers:
IScheduler.PauseAll: Pause all triggers - similar to calling PauseTriggers(GroupMatcher) on every group, however, after using this method ResumeAll() must be called to clear the scheduler's state of 'remembering' that all new triggers will be paused as they are added.
IScheduler.PauseTriggers: Pause all of the ITriggers in the groups matching.
IScheduler.PauseJobs: Pause all of the IJobDetails in the matching groups - by pausing all of their ITriggers.
IScheduler.PauseJob: Pause the IJobDetail with the given key - by pausing all of its current ITriggers.
The difference between Pause and StandBy methods may help you to understand what and when will be started:
The Pause methods are used to pause all the existing triggers you have added to scheduler only. This affect existing triggers only, and scheduler is still RUNNING! Any new job/trigger added will still run, and it's not paused! You would have to call Resume to unflag those paused triggers to get them running again.
The Standby is used to place the entire scheduler in "not working" mode, meaning no jobs or triggers will be fire or run, including ones already scheduled, or new ones added. Not until you call Start again.
Related
How can I send all resource units from a resource pool to maintenance or break whenever another event in another block occurs?
I'm looking for something like: resourcePool.startMainteinance()
and write it inside a "On start" box in some other block of the flowchart. Of course then I would need to end the maintenance with something like resourcePool.stopMainteinance() and resume all the tasks the resource units were executing.
Any idea? or some idea to pause manually all resources from executing their task and then resume them?
Note: suspending the agent that seized in the size block with the code SizeBlock.suspend() and SizeBlock.resume() is not an option because the resources have preparation tasks and those tasks also need to be paused.
Thank you!
You should use the Downtime block that is designed for this setup.
You can control it any way you like. In your case, myDowntimeblock.startTask(someAgent) and stopTask(sameAgent) work.
Also check the example model named "Maintenance of a Coffee machine": It shows all the other ways of using the block.
We're using Quartz 1.8.6 in our app. We are using CronTriggers for hourly and nightly jobs. We would like to set things up such that if there is a misfire, we want to skip the job until the next cron time rolls around.
For simple jobs, it appears you can do a
nightlyTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT);
However, it appears that this does not work with CronTrigger. What is the Misfire instruction to use in this case?
You want to use CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING.
SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT is telling Quartz that, upon one or more misfires, it must:
reschedule the trigger to fire upon the next scheduled date (not firing, i.e. ignoring, missed executions).
Also, set the "repetitions left" counter as if all missed executions had run correctly (not accounting for missed runs either).
So basically this misfire instruction tells Quartz to do nothing at all, smile and keep going like nothing ever happened. The KEEP CALM of misfire instructions.
The equivalent instruction for Cron triggers is much more aptly named: CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING.
So it seems that I can't schedule an object that extends bukkitrunnable again even though the first scheduled instance is canceled.
for example, the following code is executed when the Player right clicks
try {
blizzard.cancel();
}
finally {
blizzard.runTaskTimer(Main.plugin, 0, 1);
}
Where blizzard is an object that extends BukkitRunnable
The first time runs just fine but never runs again no matter how many times I right click. What am I doing wrong?
**Each player can have their own blizzard object. When a player right clicks with a hoe in hand, Blizzard drops a snowball at a random location around that player. Blizzard drops one snowball every run command and runs until it reaches a set number of runs. Then blizzard cancels itself. However, scheduling Blizzard to run while it is already running throws an IllegalStateException, meaning I have to cancel the current Blizzard to schedule it to run again. The problem is that doing so doesn't seem to properly schedule Blizzard to run again - it only runs the very first time it is scheduled.
By default, Bukkit does not allow runnables to be rescheduled even after they are cancelled. If you learned about Threads then you will remember that when a Thread is terminated, it can not be restarted. Bukkit follows this same logic when it comes to Runnable instances. A terminated (cancelled) Runnable can not be restarted. You must create a new Runnable instance if you wish to have that event occur again.
To have a Runnable run multiple times, you are on the right track. The BukkitScheduler.runTaskTimer method will run a task repeatedly until it is cancelled. If in your Listener you run Bukkit.getScheduler().runTaskTimer(Main.plugin, new Blizzard(), 0, 1); your Blizzard object will run repeatedly until it cancels itself. (You can also use blizzard.runTaskTimer(Main.plugin, 0, 1); from within the Blizzard constructor to automatically schedule the Runnable when it is created.)
If you keep an internal counter for how many times it has run, and increment that timer every run() method, you can cancel your Runnable after it has run a certain amount of times.
I have two timers running simultaneously. The first timer triggers every 1 second and takes 0.2 seconds to run. The second timer triggers every 20 minutes and takes 5 minutes to run. I would like to have the first timer continue triggering during the 5 minutes it takes the second timer execute its callback. In practice, during the second timer's callback the first timer does not trigger. Is it possible to configure the timers to execute the way I want?
There is a workaround, depending on how your timer callbacks' work is structured. If the long timer callback is running a long loop or sequence of calls to different functions, you can insert drawnow() or pause(0.01) calls to make it yield to Matlab's event dispatch queue, which will handle pending handle graphics and timer events, including your other Timer's trigger.
It's sort of like old-school cooperative multitasking where each thread had to explicitly yield control to other threads, instead of being pre-empted by the system's scheduler. Matlab is single-threaded with respect to M-code execution. When a Matlab function is running, events that get raised are put on an event queue and wait until the function finishes and returns to the command prompt, or drawnow(), pause(), uiwait() or a similar function is called. This is how you keep a Matlab GUI responsive, and is documented under their Handle Graphics stuff. But Matlab timer objects use the same event queue for their callbacks. (At least as of a couple versions ago; this is only semi-documented and might change.) So you can manage their liveness with the same functions. You may also need to tweak BusyMode on your timers.
This is kind of a hack but it should get you basic functionality as long as you don't need precise timing, and don't need the callbacks' code to actually run in parallel. (Whichever timer callback has yielded will wait for the other one to finish before proceeding with its own work.)
If the long callback is really blocked on a long operation that you can't stick drawnow calls in to, you're out of luck with basic Matlab and will need to use one of the workarounds the commenters suggest.
I am writing a kind of start - pause - resume - pause - resume -(at regular intervals) kind of job in Quartz. I am using a SimpleTrigger for initial experimentation.
I would like to how I can find the time a job has been running. I looked at the Scheduler class and there were no methods directly to find it.
Could some one suggest me a way of finding how long a job has been running?
Thanks,
Abi
Call scheduler.getCurrentlyExecutingJobs() to get the set of job's currently executing (or more precisely to get the JobExecutionContext of each).
Then you can call getFireTime() on the JobExecutionContext to see what time the execution started.