Hi David,
On 16. 09. 21 21:46, David Hoffer wrote:
> I see Quarkus has a quarkus-scheduler module, I have a few questions
> regarding this. Currently our app handles this via Java ExecutorService.
>
> 1. What are the advantages to using quarkus-scheduler vs.
> Executors.newXXX()?
a. The declarative @Scheduled methods API
-
https://quarkus.io/guides/scheduler-reference#scheduled-methods
b. Quarkus manages the underlying shared executor for you (and it's
configurable)
c. Integrated metrics
-
https://quarkus.io/guides/scheduler-reference#metrics
d. Integrated in Dev UI - you can for example trigger the job manually...
e. You can also leverage the same API and functionality together with
the Quartz library:
https://quarkus.io/guides/quartz
> 2. Currently we can configure these at runtime to be enabled/disabled,
> is there a way to do that with quarkus-scheduler? E.g. I know I can
> create a Scheduler to trigger every 10 seconds but can that be disabled
> at runtime so that it doesn't trigger or would I have to just configure
> it to be a noop when triggered if disabled?
I'm not sure I fully understand but you can specify the interval via a
config property, e.g. @Scheduled(every = "${myMethod.every}"), the "off"
and "disabled" values just disable the method, and even disable the
method if no property is defined: @Scheduled(every =
"${myMethod.every:off}"). See also
https://quarkus.io/guides/scheduler-reference#intervals.
Alternatively, you can pause/resume a scheduled method that has a
specific identity, e.g. @Scheduled(identity = "myScheduledMethod"). You
can do so via the injected scheduler:
https://quarkus.io/guides/scheduler-reference#scheduler
> 3.What about cases where I just need some logic to run in a new thread
> until the app is shut down, does Quarkus have a substitute for
> Executors.newSingleThreadExecutor()?
Does it need to be a new thread? In general, you can declare a CDI
observer for the ShutdownEvent:
https://quarkus.io/guides/lifecycle#listening-for-startup-and-shutdown-events
>
> -Dave
>
> --
> You received this message because you are subscribed to the Google
> Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
quarkus-dev...@googlegroups.com
> <mailto:
quarkus-dev...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/quarkus-dev/c1485bff-ace0-4023-846d-763718b42fe1n%40googlegroups.com
> <
https://groups.google.com/d/msgid/quarkus-dev/c1485bff-ace0-4023-846d-763718b42fe1n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Martin Kouba
Software Engineer
Red Hat, Czech Republic