I have an Akka actor that validates random data and makes some changes to it based on that data's show time and updates it. Currently what I'm doing is using this code inside a controller:
static ActorRef instance = Akka.system().actorOf(new Props(ValidateAndChangeIt.class));
static {
Akka.system().scheduler().schedule(
Duration.Zero(),
Duration.create(5, TimeUnit.MINUTES),
instance, "VALIDATE"
);
}
The problem with using this inside a controller is that someone has to access a page processed by that controller for the actor to start, and if this doesn't happen, everything stays paused.
Is there a way to do this at server start? I actually don't know how it behaves if the actor generates an exception. Does it stop future schedules or does it continue? In case it doesn't, is there any way of making the actor re-schedule in case any crash or error?