Is there a mechanism I can use to kill an actor after it has been created for 20 seconds ?
Reading about the various SuperVisor strategies at http://doc.akka.io/docs/akka/snapshot/java/fault-tolerance.html
it seems killing an actor is all based on message passing of exceptions ?
You can use the Scheduler to send a PoisonPill message to the actor after 20s, that will kill the actor automatically when the actor processes that message; no extra code required within the actor. If you want to kill the actor straight away, and not wait for the poison pill to work its way through the message queue then use stop instead.
system.scheduler().scheduleOnce(Duration.create(20, TimeUnit.SECONDS),
new Runnable() {
@Override
public void run() {
testActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
}
}, system.dispatcher());