Does spring #Scheduled annotation use system's cron? (e.g. ubuntu cron) or spring's or tomcat's cron? - spring

Does spring #Scheduled annotation use system's cron? (e.g. ubuntu cron) or spring's or tomcat's cron?
So can it work on any os? Or only where crontab exists on OS's level? What is under the hood there? (just a link to manual would be enough)

It's using Unix cron. Please see documentation:
Schedule annotation

Related

Spring task:scheduled or #Scheduler to restrict a Job to run in multiple instance

I have one #Scheduler job which runs on multiple servers in a clustered environment. However I want to restrict the job to run in only in one server and other servers should not run the same job once any other server has started it .
I have explored Spring Batch has lock mechanism using some Database table , but looking for any a solution only in spring task:scheduler.
I had the same problem and the solution what I implemented was a the Lock mechanism with Hazelcast and to made it easy to use I also added a proper annotation and a bit of spring AOP for that. So with this trick I was able to enforce a single schedule over the cluster done with a single annotation.
Spring Batch has this nice functionality that it would not run the job with same job arguments twice.
You can use this feature so that when a spring batch job kicks start in another server it does not run.
Usually people pass a timestamp as argument so it will by pass this logic, which you can change it.

When spring-boot app multi-node deploy, how to handle cron job?

When I use spring task handle a simple sync job! But when I deploy multi-node, how I make sure the cron job just run one time.
Maybe you say that:
1. Use distributed-lock control a flag before the crob job run.
2. Integrated quartz cluster function.
But I hope spring task #EnableScheduling can add a flag argument, so as we can set a flag when launch app.
We are using https://github.com/lukas-krecan/ShedLock with success, zookeeper provider in particular.
Spring boot, in a nutshell, doesn't allow any type of coordination between multiple instances
of the same microservice.
All the work of such a coordination is done by the third parties that spring boot gets integrated with.
One example of this is indeed a #Scheduled annotation.
Another is DB migration support via flyway.
When many nodes start and the migration has to be done, flyway is responsible to lock the migration table by itself, spring boot has nothing to do with it.
So, bottom line, there is no such support and all options that you've raised can work.

Spring Boot Batch - execluding JobLauncherCommandLineRunner

i have a simple Spring Batch job configured in Spring Boot (something similar to the spring guides). at startup, it auto-detects and invokes JobLauncherCommandLineRunner and i want to stop that behavior. I want the job to only be fired by a defined trigger elsewhere in the app, not on startup.
i've tried the #ComponentScan(excludeFilters... approach but it still gets invoked.
any way to switch off this 'helper' class?
You can set spring.batch.job.enabled=false or you can set spring.batch.job.names=none (see source code for details).

run commands per boot via cloud config

I am passing cloud config via --user-data-file argument when starting ec2 instance from canonic ubuntu images.
It works well but the problem is that some of its commands need to run every boot (i.e. when we stop/start or reboot the instance). Is there a way (or section in cloud config) that allows to describe commands that should run on every boot, not only upon instance creation?
You do not need cloud-init to do boot time command execution. Things you want to look at is crontab, upstart scripts, /etc/rc.local and /etc/init.d. There are a lot of options. It depends on the distribution as well.

Couple of questions about spring quartz

I'm thinking of building spring quartz into my spring mvc web application. I have a few questions about it that I could not properly find an answer.
If I want to use cron triggers for spring quartz does quartz execute the job using java system time or the operating system time?
I am planning to have a properties file to hold all of my cron triggers. If someone goes and changes a cron trigger for an ad-hoc execution of a job will quartz automatically pick up the changes in the file? Or is there a way for me to tell quartz how to do this if it is not default behavior.
I have been reading about spring batch admin console recently. Sounds like a nice gui tool to reschedule jobs. Can it be used to make ad-hoc changes to crontab triggers? Or is there another gui tool I could use to manage the job triggers?
thanks in advance
Quartz
Quartz uses custom thread scheduler (org.quartz.core.QuartzScheduler) which use java system time. It can integrate commonj interface to be JEE (WAS and Weblogic) interoperable.
Reload configuration: read Quartz: How to reload jobs and triggers with org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin?
Spring batch admin console is for spring batch and is bale to monitor batches activity
Reload configuration Using API
Generally speaking you can use quartz API programmatically (I use them):
JobDetail job = new JobDetail();
job.setName("myJob");
job.setJobClass(MyJob.class);
CronTrigger trigger = new CronTrigger();
trigger.setName("myTriggerName");
trigger.setCronExpression("0/30 * * * * ?");
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
these APIs provide you fine control.
Reload configuration JMX way
You can control the Qurtz scheduler through RemoteMBeanScheduler:
An implementation of the Scheduler interface that remotely proxies all method calls to the equivalent call on a given QuartzScheduler instance, via JMX.

Resources