Sending a PoisonPill to an Actor in Java

As mentioned in my reply to the comment above, this does not work in Idea or when using gradle to compile. It is in fact a compilation error since the sender ActorRef is required. I know the previous answers are old, and i'm not sure if this was a change in the api, so for anyone having a similar issue you should be using :

target.tell(PoisonPill.getInstance(), ActorRef.noSender());

For reference see : http://doc.akka.io/docs/akka/snapshot/java/lambda-actors.html#PoisonPill


Please read the Akka documentation, we've spent a lot of time creating it:

PoisonPill

You can also send an actor the akka.actor.PoisonPill message, which will stop the actor when the message is processed. PoisonPill is enqueued as ordinary messages and will be handled after messages that were already queued in the mailbox.

Use it like this:

   import static akka.actor.Actors.*;
   myActor.tell(poisonPill());
  • http://doc.akka.io/docs/akka/2.0.3/java/untyped-actors.html#PoisonPill

The above approach has been deprecated since 2.0.2, this is the new API:

ActorRef ref = system.actorOf(new Props(JavaAPITestActor.class));
ref.tell(PoisonPill.getInstance());

The above compiles on my machine so you might have some issue in IDEA? Try to compile it with javac and see if that works.