No, it doesn’t
# http4k
s
No, it doesn’t
s
So the standard is to use the ScheduledExecutorService?
s
That’s the simplest way to have a background executor in the JVM, as far as I know
v
So the standard is to use the ScheduledExecutorService?
Especially in Cloud environment that would be an antipattern and probably wouldn't even work, it would be better to use an external scheduler which would invoke your service via message or http call
s
What would be wrong with using a scheduled task?
v
in cloud environment the services are suspended when not executing request, so no background work would be done
f
Another problem would be if you have x number of instances of the app running and all of them have a scheduled executor service running, then all of them would execute the task at the same time. Another reason to use an external scheduler service or app.
Unless the task does apply to each instance, like refreshing some cached values or running garbage collect at specific times
s
So the proper answer is “it depends”
s
Very much so.
r
FWIW we are using
Executors.newSingleThreadScheduledExecutor()
for running the background task that renew the JWK Set.