I have following Spring job to run after every 30 minutes. Please check my cron expression, is that correct?
\"0 0 0 * * 30\"
H
If someone is using @Sceduled this might work for you.
@Scheduled(cron = "${name-of-the-cron:0 0/30 * * * ?}")
This worked for me.
According to the Quartz-Scheduler Tutorial
It should be value="0 0/30 * * * ?"
The field order of the cronExpression is
1.Seconds
2.Minutes
3.Hours
4.Day-of-Month
5.Month
6.Day-of-Week
7.Year (optional field)
Ensure you have at least 6 parameters or you will get an error (year is optional)
in web app java spring what worked for me
cron="0 0/30 * * * ?"
This will trigger on for example 10:00AM then 10:30AM etc...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<beans profile="cron">
<bean id="executorService" class="java.util.concurrent.Executors" factory-method="newFixedThreadPool">
<beans:constructor-arg value="5" />
</bean>
<task:executor id="threadPoolTaskExecutor" pool-size="5" />
<task:annotation-driven executor="executorService" />
<beans:bean id="expireCronJob" class="com.cron.ExpireCron"/>
<task:scheduler id="serverScheduler" pool-size="5"/>
<task:scheduled-tasks scheduler="serverScheduler">
<task:scheduled ref="expireCronJob" method="runTask" cron="0 0/30 * * * ?"/> <!-- every thirty minute -->
</task:scheduled-tasks>
</beans>
</beans>
I dont know why but this is working on my local develop and production, but other changes if i made i have to be careful because it may work local and on develop but not on production
Graphically, the cron syntax for Quarz is (source):
+-------------------- second (0 - 59)
| +----------------- minute (0 - 59)
| | +-------------- hour (0 - 23)
| | | +----------- day of month (1 - 31)
| | | | +-------- month (1 - 12)
| | | | | +----- day of week (0 - 6) (Sunday=0 or 7)
| | | | | | +-- year [optional]
| | | | | | |
* * * * * * * command to be executed
So if you want to run a command every 30 minutes you can say either of these:
0 0/30 * * * * ?
0 0,30 * * * * ?
You can check crontab expressions using either of these:
<property name="cronExpression" value="0 0/30 * * * ?" />