0

We see there is a scheduler in JavaDocs https://helidon.io/docs/latest/apidocs/io/helidon/microprofile/faulttolerance/CommandScheduler.html

Our need is, we want to have few REST Endpoints and also a job to process some info, would it be possible in helidon MP to have both in a single jvm process?

Thank you Ananthram

1 Answers1

3

CommandScheduler is part of Fault tolerance, what you need is ScheduledThreadPoolSupplier.

To make it little prettier with reactive api(works in both flavors of Helidon 2.x):

ScheduledThreadPoolSupplier scheduledThreadPoolSupplier =
                ScheduledThreadPoolSupplier.builder()
                        .threadNamePrefix("scheduled-test-")
                        .corePoolSize(2)
                        .build();

Multi.interval(5, TimeUnit.SECONDS, scheduledThreadPoolSupplier.get())
                .map(l -> "invocation number " + l)
                // max number of invocations
                .limit(5)
                .forEach(s -> System.out.println("Scheduled " + s))
                .await();

scheduledThreadPoolSupplier.get().shutdown();

> Scheduled invocation number 0
> Scheduled invocation number 1
> Scheduled invocation number 2
> Scheduled invocation number 3
> Scheduled invocation number 4

But be aware! This job would be scheduled on every instance of your service, I would suggest to check out Kubernetes CronJobs first.

https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/

Happy coding!

Daniel Kec
  • 529
  • 2
  • 8