We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

P Satish Patro • 6 years ago

show how to take it dynamically from applocation.proerties file

Viny Machado • 6 years ago

I found out that Spring uses its own cron expression format. The thing is, I got an app where the user can input some cron expression to schedule a task so I'd like to take that cron expression and use with CronTrigger.

Is there any way to convert a normal cron expression into a Spring format?

Bhargavi Yamani • 6 years ago

while I am try to run the end part of spring boot application, it is continuously running. Please, tell me how to get proper solution for this problem. Because of that, i couldn't check my result.

Misha • 7 years ago

Is there a way to specify a user to run this scheduled job? Like we setup a crontab for a user?

MoPHL • 7 years ago

Hi, very good and helpful article!

Just a question, in the case of the fixed rate tasks, if you want to stop/interrupt the task, how would you do it?
Thanks.

Eugene Shamkin • 7 years ago

Thank you!

Raj • 7 years ago

While running in a Clustered environment, the scheduled task will run twice.
How can we make sure it is only run once.

Neshant Sharma • 7 years ago
Binh Thanh Nguyen • 7 years ago

Thanks, nice tip

disqus_6Nf2aggRjN • 7 years ago

disqus_NlDD94vXk9 ):

TOPnTOPS • 7 years ago

Hi, I have a scenario where it's pretty common to change the system date. I'm using @Scheduled with cron expression, it works fine before changing the date, but after changing the date, the scheduled method doesn't run, so I resolve to restarting the app every time a change in system date happens. Do you think the @Scheduled annotation uses a different date object from the system date?

温锐 • 7 years ago

how to get ThreadPoolTaskScheduler bean?

Prashant • 7 years ago

Please extend this article by adding scheduling task using using file watcher. Thanks

DTAP GmbH • 8 years ago

Last time I checked, SimpleDateFormat was not thread safe. You may want to create a new instance in each of the four methods and not as a static field.

Rajeev Singh • 8 years ago

DTAP GmbH You're right! Thanks for pointing this out. I think I'll change this to Java 8's DateTimeFormatter.
DateTimeFormatter is immutable and thread-safe.

DTAP GmbH • 8 years ago

That's an even better solution.

Wallace Garbim • 8 years ago

Hi, I have a problem when using @Schedule cron. Simple does not work. If I change to fixedRate for example works, but not using cron. I did the same way as you are showing.
I am using tomcat 7 running in a Mac for development. Do you have any idea what could be?

@Scheduled(cron = "*/10 * * * * *", zone = "Europe/Madrid")

Thank you

Rajeev Singh • 8 years ago

I tried the cron expression that you're using in my local system and it is working fine. Here are the logs -


2017-12-20 22:59:30.001 INFO 35254 --- [led-task-pool-1] c.example.schedulerdemo.ScheduledTasks : Cron Task :: Execution Time - 22:59:30
2017-12-20 22:59:40.001 INFO 35254 --- [led-task-pool-1] c.example.schedulerdemo.ScheduledTasks : Cron Task :: Execution Time - 22:59:40

I can't tell you why it's not working for you unless I see your code. It would be great if you can create a pull request with your code in the github repository.