I have an actor that is intended to do one long running job and not receive any more messages:
actor {
def receieve => longRunningJob()
}
How can I debug the killing of this actor?
I have followed the documentation that says "Within an actor, you can stop a child actor by using the context reference:"
context.stop(childActor)
I have also tried sending the child a Kill message, a Stop message, and a PoisonPill message, but nothing stops it while in the middle of the long running job.
It is not that stopping the actor is failing, as much as that the Actors is never given the opportunity to process the messages related to stopping it. Actors are single-threaded by design and should be constructed to do as little blocking in the message loop as possible.
What you are really asking in this case is "how to interrupt a thread" since longRunningJob
appears to be a single-threaded, blocking, time intensive task and the answer is, there really is no good way.
An Actor that goes into a state of "processing a long running job" should do so without blocking the message loop itself, either by having the job itself be asynchronous (leaving it orphaned and running if the actor is stopped) or the job itself consists of lots of small steps, each of which triggers the next step with a message back to itself, so that a) you can receive other messages and b) have the opportunity to interrupt the job mid-way through.