Skip to content

long running scheduled task #45843

Answered by manovotn
CluelessAardvark asked this question in Q&A
Discussion options

You must be logged in to vote

I think you would need an executor to delegate the task to so that you don't block the thread used for scheduler invocations.
You can still use scheduler to trigger the task regularly but offload the task itself to another thread.
From the top of my head, I recall you can @Inject ExecutorService or ManagedExecutor. The latter allows for some context propagation but that might end up being more complicated if your tasks are this long.

Another thing is that you can @Inject ScheduledExecutorService - with this you could schedule either a one-off task or even a periodic one so based on what exactly you need, this could replace the scheduler altogether.

Replies: 4 comments 22 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
16 replies
@gsmet
Comment options

@manovotn
Comment options

@mkouba
Comment options

mkouba Jan 31, 2025
Collaborator

@gsmet
Comment options

@mkouba
Comment options

mkouba Jan 31, 2025
Collaborator

Answer selected by CluelessAardvark
Comment options

You must be logged in to vote
5 replies
@mkouba
Comment options

mkouba Jan 31, 2025
Collaborator

@manovotn
Comment options

@mkouba
Comment options

mkouba Jan 31, 2025
Collaborator

@jcjveraa
Comment options

@manovotn
Comment options

Comment options

You must be logged in to vote
1 reply
@manovotn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
6 participants