Spring's @Scheduled(fixedDelay=…) stops at midnight
I have a Spring Boot application that uses a @Scheduled
annotation with a fixed delay. The annotation is used in different classes with different delays. However, at midnight every day all scheduled tasks stop running.
Does anyone know why this might be happening? I can't find any explanation online.
(I am using version 2.0.2.RELEASE of Spring Boot and 5.0.6.RELEASE of Spring Core.)
Thanks in advance!
java spring spring-boot spring-scheduled
add a comment |
I have a Spring Boot application that uses a @Scheduled
annotation with a fixed delay. The annotation is used in different classes with different delays. However, at midnight every day all scheduled tasks stop running.
Does anyone know why this might be happening? I can't find any explanation online.
(I am using version 2.0.2.RELEASE of Spring Boot and 5.0.6.RELEASE of Spring Core.)
Thanks in advance!
java spring spring-boot spring-scheduled
2
can I see one of your scheduled cron expression that stops?
– Kartik
Nov 15 '18 at 1:21
Make sure that the OS you are running on doesn't kill threads, it might kill the actual scheduling thread.
– M. Deinum
Nov 15 '18 at 8:03
The @Scheduled annotation doesn't use the cron feature. It looks like this: @Scheduled(initialDelay = 10000, fixedDelay = 60000).
– Steven P.
Nov 15 '18 at 15:53
I'm not sure how to see if my OS is killing threads, but I will dump the Java threads today before and after midnight to see if some are disappearing. I don't think the OS is doing it because I have some long running threads not managed by Spring and they continue to work. FYI, I am running CentOS 7 inside of a Docker container. The host is Debian 9.
– Steven P.
Nov 15 '18 at 15:57
add a comment |
I have a Spring Boot application that uses a @Scheduled
annotation with a fixed delay. The annotation is used in different classes with different delays. However, at midnight every day all scheduled tasks stop running.
Does anyone know why this might be happening? I can't find any explanation online.
(I am using version 2.0.2.RELEASE of Spring Boot and 5.0.6.RELEASE of Spring Core.)
Thanks in advance!
java spring spring-boot spring-scheduled
I have a Spring Boot application that uses a @Scheduled
annotation with a fixed delay. The annotation is used in different classes with different delays. However, at midnight every day all scheduled tasks stop running.
Does anyone know why this might be happening? I can't find any explanation online.
(I am using version 2.0.2.RELEASE of Spring Boot and 5.0.6.RELEASE of Spring Core.)
Thanks in advance!
java spring spring-boot spring-scheduled
java spring spring-boot spring-scheduled
asked Nov 15 '18 at 1:10
Steven P.Steven P.
675312
675312
2
can I see one of your scheduled cron expression that stops?
– Kartik
Nov 15 '18 at 1:21
Make sure that the OS you are running on doesn't kill threads, it might kill the actual scheduling thread.
– M. Deinum
Nov 15 '18 at 8:03
The @Scheduled annotation doesn't use the cron feature. It looks like this: @Scheduled(initialDelay = 10000, fixedDelay = 60000).
– Steven P.
Nov 15 '18 at 15:53
I'm not sure how to see if my OS is killing threads, but I will dump the Java threads today before and after midnight to see if some are disappearing. I don't think the OS is doing it because I have some long running threads not managed by Spring and they continue to work. FYI, I am running CentOS 7 inside of a Docker container. The host is Debian 9.
– Steven P.
Nov 15 '18 at 15:57
add a comment |
2
can I see one of your scheduled cron expression that stops?
– Kartik
Nov 15 '18 at 1:21
Make sure that the OS you are running on doesn't kill threads, it might kill the actual scheduling thread.
– M. Deinum
Nov 15 '18 at 8:03
The @Scheduled annotation doesn't use the cron feature. It looks like this: @Scheduled(initialDelay = 10000, fixedDelay = 60000).
– Steven P.
Nov 15 '18 at 15:53
I'm not sure how to see if my OS is killing threads, but I will dump the Java threads today before and after midnight to see if some are disappearing. I don't think the OS is doing it because I have some long running threads not managed by Spring and they continue to work. FYI, I am running CentOS 7 inside of a Docker container. The host is Debian 9.
– Steven P.
Nov 15 '18 at 15:57
2
2
can I see one of your scheduled cron expression that stops?
– Kartik
Nov 15 '18 at 1:21
can I see one of your scheduled cron expression that stops?
– Kartik
Nov 15 '18 at 1:21
Make sure that the OS you are running on doesn't kill threads, it might kill the actual scheduling thread.
– M. Deinum
Nov 15 '18 at 8:03
Make sure that the OS you are running on doesn't kill threads, it might kill the actual scheduling thread.
– M. Deinum
Nov 15 '18 at 8:03
The @Scheduled annotation doesn't use the cron feature. It looks like this: @Scheduled(initialDelay = 10000, fixedDelay = 60000).
– Steven P.
Nov 15 '18 at 15:53
The @Scheduled annotation doesn't use the cron feature. It looks like this: @Scheduled(initialDelay = 10000, fixedDelay = 60000).
– Steven P.
Nov 15 '18 at 15:53
I'm not sure how to see if my OS is killing threads, but I will dump the Java threads today before and after midnight to see if some are disappearing. I don't think the OS is doing it because I have some long running threads not managed by Spring and they continue to work. FYI, I am running CentOS 7 inside of a Docker container. The host is Debian 9.
– Steven P.
Nov 15 '18 at 15:57
I'm not sure how to see if my OS is killing threads, but I will dump the Java threads today before and after midnight to see if some are disappearing. I don't think the OS is doing it because I have some long running threads not managed by Spring and they continue to work. FYI, I am running CentOS 7 inside of a Docker container. The host is Debian 9.
– Steven P.
Nov 15 '18 at 15:57
add a comment |
3 Answers
3
active
oldest
votes
I'm not sure what do you mean about stopping running.
But the first work you need to do is starting your schedules on different threads and put them into a queue.
If stopping means suspending for a while,then you create a new schedule that make other schedules sleep some time at midnight.Maybe the new schedule should have be started when the thread are sleeping,and the way to prevent is to make sure only one schedule(I mean same kind of schedule) could be put in the queue at the same time.
If you just mean kill all other schedule at midnight,you just need to start your midnight schedules and kill others.
So sorry about my poor English,hope this could help you.
Thanks for your response. I already set a pool size greater than the number of scheduled tasks on both the scheduler and executor. If I understand correctly, that means they should be on different threads.
– Steven P.
Nov 15 '18 at 16:15
When I said stopping, I meant the tasks are completely stopped as far as I can tell. Yesterday I left the application up for more than 8 hours after the last execution and there was never any more activity from the tasks.
– Steven P.
Nov 15 '18 at 16:17
The tasks cant start again?Were you shutdown the thread pool?If the thread pool is still running,what if you execute a task by a Scheduler like ThreadPoolTaskScheduler?
– AokoQin
Nov 16 '18 at 5:19
add a comment |
@Scheduled(fixedDelay = 1000)
void scheduleFixedDelayTask()
System.out.println(
"Fixed delay task - " + System.currentTimeMillis() /
1000);
In this case, the duration between the end of last execution and the start of next execution is fixed. The task always waits until the previous one is finished.
This option should be used when it’s mandatory that the previous execution is completed before running again.
So maintain the delay such a way that the previous execution completed.
Hope it helps.
add a comment |
Thanks to everyone who replied.
As it turns out, this was not an issue with Spring. It appeared the tasks stopped because the logs stopped. What really happened was that our scripts that tail the logs were not smart enough to handle log files that roll at midnight (face palm).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311056%2fsprings-scheduledfixeddelay-stops-at-midnight%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure what do you mean about stopping running.
But the first work you need to do is starting your schedules on different threads and put them into a queue.
If stopping means suspending for a while,then you create a new schedule that make other schedules sleep some time at midnight.Maybe the new schedule should have be started when the thread are sleeping,and the way to prevent is to make sure only one schedule(I mean same kind of schedule) could be put in the queue at the same time.
If you just mean kill all other schedule at midnight,you just need to start your midnight schedules and kill others.
So sorry about my poor English,hope this could help you.
Thanks for your response. I already set a pool size greater than the number of scheduled tasks on both the scheduler and executor. If I understand correctly, that means they should be on different threads.
– Steven P.
Nov 15 '18 at 16:15
When I said stopping, I meant the tasks are completely stopped as far as I can tell. Yesterday I left the application up for more than 8 hours after the last execution and there was never any more activity from the tasks.
– Steven P.
Nov 15 '18 at 16:17
The tasks cant start again?Were you shutdown the thread pool?If the thread pool is still running,what if you execute a task by a Scheduler like ThreadPoolTaskScheduler?
– AokoQin
Nov 16 '18 at 5:19
add a comment |
I'm not sure what do you mean about stopping running.
But the first work you need to do is starting your schedules on different threads and put them into a queue.
If stopping means suspending for a while,then you create a new schedule that make other schedules sleep some time at midnight.Maybe the new schedule should have be started when the thread are sleeping,and the way to prevent is to make sure only one schedule(I mean same kind of schedule) could be put in the queue at the same time.
If you just mean kill all other schedule at midnight,you just need to start your midnight schedules and kill others.
So sorry about my poor English,hope this could help you.
Thanks for your response. I already set a pool size greater than the number of scheduled tasks on both the scheduler and executor. If I understand correctly, that means they should be on different threads.
– Steven P.
Nov 15 '18 at 16:15
When I said stopping, I meant the tasks are completely stopped as far as I can tell. Yesterday I left the application up for more than 8 hours after the last execution and there was never any more activity from the tasks.
– Steven P.
Nov 15 '18 at 16:17
The tasks cant start again?Were you shutdown the thread pool?If the thread pool is still running,what if you execute a task by a Scheduler like ThreadPoolTaskScheduler?
– AokoQin
Nov 16 '18 at 5:19
add a comment |
I'm not sure what do you mean about stopping running.
But the first work you need to do is starting your schedules on different threads and put them into a queue.
If stopping means suspending for a while,then you create a new schedule that make other schedules sleep some time at midnight.Maybe the new schedule should have be started when the thread are sleeping,and the way to prevent is to make sure only one schedule(I mean same kind of schedule) could be put in the queue at the same time.
If you just mean kill all other schedule at midnight,you just need to start your midnight schedules and kill others.
So sorry about my poor English,hope this could help you.
I'm not sure what do you mean about stopping running.
But the first work you need to do is starting your schedules on different threads and put them into a queue.
If stopping means suspending for a while,then you create a new schedule that make other schedules sleep some time at midnight.Maybe the new schedule should have be started when the thread are sleeping,and the way to prevent is to make sure only one schedule(I mean same kind of schedule) could be put in the queue at the same time.
If you just mean kill all other schedule at midnight,you just need to start your midnight schedules and kill others.
So sorry about my poor English,hope this could help you.
answered Nov 15 '18 at 3:12
AokoQinAokoQin
894
894
Thanks for your response. I already set a pool size greater than the number of scheduled tasks on both the scheduler and executor. If I understand correctly, that means they should be on different threads.
– Steven P.
Nov 15 '18 at 16:15
When I said stopping, I meant the tasks are completely stopped as far as I can tell. Yesterday I left the application up for more than 8 hours after the last execution and there was never any more activity from the tasks.
– Steven P.
Nov 15 '18 at 16:17
The tasks cant start again?Were you shutdown the thread pool?If the thread pool is still running,what if you execute a task by a Scheduler like ThreadPoolTaskScheduler?
– AokoQin
Nov 16 '18 at 5:19
add a comment |
Thanks for your response. I already set a pool size greater than the number of scheduled tasks on both the scheduler and executor. If I understand correctly, that means they should be on different threads.
– Steven P.
Nov 15 '18 at 16:15
When I said stopping, I meant the tasks are completely stopped as far as I can tell. Yesterday I left the application up for more than 8 hours after the last execution and there was never any more activity from the tasks.
– Steven P.
Nov 15 '18 at 16:17
The tasks cant start again?Were you shutdown the thread pool?If the thread pool is still running,what if you execute a task by a Scheduler like ThreadPoolTaskScheduler?
– AokoQin
Nov 16 '18 at 5:19
Thanks for your response. I already set a pool size greater than the number of scheduled tasks on both the scheduler and executor. If I understand correctly, that means they should be on different threads.
– Steven P.
Nov 15 '18 at 16:15
Thanks for your response. I already set a pool size greater than the number of scheduled tasks on both the scheduler and executor. If I understand correctly, that means they should be on different threads.
– Steven P.
Nov 15 '18 at 16:15
When I said stopping, I meant the tasks are completely stopped as far as I can tell. Yesterday I left the application up for more than 8 hours after the last execution and there was never any more activity from the tasks.
– Steven P.
Nov 15 '18 at 16:17
When I said stopping, I meant the tasks are completely stopped as far as I can tell. Yesterday I left the application up for more than 8 hours after the last execution and there was never any more activity from the tasks.
– Steven P.
Nov 15 '18 at 16:17
The tasks cant start again?Were you shutdown the thread pool?If the thread pool is still running,what if you execute a task by a Scheduler like ThreadPoolTaskScheduler?
– AokoQin
Nov 16 '18 at 5:19
The tasks cant start again?Were you shutdown the thread pool?If the thread pool is still running,what if you execute a task by a Scheduler like ThreadPoolTaskScheduler?
– AokoQin
Nov 16 '18 at 5:19
add a comment |
@Scheduled(fixedDelay = 1000)
void scheduleFixedDelayTask()
System.out.println(
"Fixed delay task - " + System.currentTimeMillis() /
1000);
In this case, the duration between the end of last execution and the start of next execution is fixed. The task always waits until the previous one is finished.
This option should be used when it’s mandatory that the previous execution is completed before running again.
So maintain the delay such a way that the previous execution completed.
Hope it helps.
add a comment |
@Scheduled(fixedDelay = 1000)
void scheduleFixedDelayTask()
System.out.println(
"Fixed delay task - " + System.currentTimeMillis() /
1000);
In this case, the duration between the end of last execution and the start of next execution is fixed. The task always waits until the previous one is finished.
This option should be used when it’s mandatory that the previous execution is completed before running again.
So maintain the delay such a way that the previous execution completed.
Hope it helps.
add a comment |
@Scheduled(fixedDelay = 1000)
void scheduleFixedDelayTask()
System.out.println(
"Fixed delay task - " + System.currentTimeMillis() /
1000);
In this case, the duration between the end of last execution and the start of next execution is fixed. The task always waits until the previous one is finished.
This option should be used when it’s mandatory that the previous execution is completed before running again.
So maintain the delay such a way that the previous execution completed.
Hope it helps.
@Scheduled(fixedDelay = 1000)
void scheduleFixedDelayTask()
System.out.println(
"Fixed delay task - " + System.currentTimeMillis() /
1000);
In this case, the duration between the end of last execution and the start of next execution is fixed. The task always waits until the previous one is finished.
This option should be used when it’s mandatory that the previous execution is completed before running again.
So maintain the delay such a way that the previous execution completed.
Hope it helps.
answered Nov 15 '18 at 4:08
Karthik PKarthik P
336
336
add a comment |
add a comment |
Thanks to everyone who replied.
As it turns out, this was not an issue with Spring. It appeared the tasks stopped because the logs stopped. What really happened was that our scripts that tail the logs were not smart enough to handle log files that roll at midnight (face palm).
add a comment |
Thanks to everyone who replied.
As it turns out, this was not an issue with Spring. It appeared the tasks stopped because the logs stopped. What really happened was that our scripts that tail the logs were not smart enough to handle log files that roll at midnight (face palm).
add a comment |
Thanks to everyone who replied.
As it turns out, this was not an issue with Spring. It appeared the tasks stopped because the logs stopped. What really happened was that our scripts that tail the logs were not smart enough to handle log files that roll at midnight (face palm).
Thanks to everyone who replied.
As it turns out, this was not an issue with Spring. It appeared the tasks stopped because the logs stopped. What really happened was that our scripts that tail the logs were not smart enough to handle log files that roll at midnight (face palm).
answered Nov 28 '18 at 16:14
Steven P.Steven P.
675312
675312
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311056%2fsprings-scheduledfixeddelay-stops-at-midnight%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
can I see one of your scheduled cron expression that stops?
– Kartik
Nov 15 '18 at 1:21
Make sure that the OS you are running on doesn't kill threads, it might kill the actual scheduling thread.
– M. Deinum
Nov 15 '18 at 8:03
The @Scheduled annotation doesn't use the cron feature. It looks like this: @Scheduled(initialDelay = 10000, fixedDelay = 60000).
– Steven P.
Nov 15 '18 at 15:53
I'm not sure how to see if my OS is killing threads, but I will dump the Java threads today before and after midnight to see if some are disappearing. I don't think the OS is doing it because I have some long running threads not managed by Spring and they continue to work. FYI, I am running CentOS 7 inside of a Docker container. The host is Debian 9.
– Steven P.
Nov 15 '18 at 15:57