1
votes

I'm starting to use Akka with Java.

  1. If I send a message to an actor that starts a cpu-bound process, is it possible to stop this actor while he is processing that message or I have to wait that it ends it? (I've seen that stop() anf kill first wait the end).

  2. How can I run actors in parallel? Is it possible to see 2 actors like 2 parallel threads and kill one of those when I want?

1
This discussion led to this issue in 2010 which Viktor Klang closed as invalid 2011. It looks like it would have added an interrupt flag on Actor that you could check similar to Thread.interrupted(). It doesn't look like such a feature ever made it in. I think you may need to invent your own way of breaking your CPU work into chunks and run one chunk per message received. - Chris Martin
so you're saying that is impossible to delete the actor thread, is only possible to divide the entire work in chunks and work one by one? Is it possible to delete an actor from the actorSystem also if it'is in a running state? - Michele
Essentially, yes. This is the nature of the JVM; threads cannot be forcefully halted. There is nothing Akka could do to change that. - Chris Martin
And is there possibility to delete an actor from the actorSystem whenever I want? - Michele
Such that it's still running after it's removed? I doubt it. - Chris Martin

1 Answers

0
votes
  1. You can't stop processing current message because it can lead to inconsistent state of your application. All you can do is not to process all the next messages by calling stop(actorRef) method.

  2. Actors ARE parallel, this is their main feature. You just create one actor, then another, send messages to them and they both run in parallel.