Search code examples
javascalaakkalifecyclehikaricp

Akka Actor LifeCycle


I'm using Akka Java API 2.5.12. I want to implement push sender. I use infinite loop with one second delay and in each iteration I fetch 50 pushes from database using Hikari Datasource Connection Pool. Then I iterate over this list of 50 pushes and in each iteration I create new Actor in this way:

final ActorRef pushSenderActor = system.actorOf(PushSenderAktor.props());
pushSenderActor.tell(push, ActorRef.noSender());

Then PushSenderAktor play their role and send push asynchronously.

My question is: Do I need to stop an actor after he has performed a push sending by context().stop(getSelf()); method, or this actor will kill himself after executing his createReceive() method? Because I don't want to contain a HollyWood in my ActorSystem.


Solution

  • You'll need to explicitly stop or send a PoisonPill

    https://doc.akka.io/docs/akka/2.5/actors.html#actor-lifecycle

    Also consider using the scheduler in a top level actor the the regular work and consider keeping actors around and using them as long term workers.