1

I'd like to spawn many Actors which execute a private method at a specific time interval. This task will need to run at the time interval indefinitely until the Actor is terminated.

All of the solutions I've seen in Java involve creating a new thread, for example Spring's TaskExecutor or using ScheduledExecutorService. Because an Actor already has its own Fiber, I see no reason to spawn a thread unless my task is very heavy.

In Elixir, this was very simple to achieve using Process.send_after().

Is there a similar way to do this in Java using Quasar?

sheldonkreger
  • 858
  • 1
  • 9
  • 25

1 Answers1

1

Fiber has method sleep(long millis), so you can easily create a fiber which executes periodically with:

while (!end) {
    doTask();
    sleep(period);
}
Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38