Note that there are some explanatory texts on larger screens.

plurals
  1. POAkka Actor not terminating if an exception is thrown
    primarykey
    data
    text
    <p>I am currently trying to get started with Akka and I am facing a weird problem. I've got the following code for my Actor:</p> <pre><code>class AkkaWorkerFT extends Actor { def receive = { case Work(n, c) if n &lt; 0 =&gt; throw new Exception("Negative number") case Work(n, c) =&gt; self reply n.isProbablePrime(c); } } </code></pre> <p>And this is how I start my workers:</p> <pre><code>val workers = Vector.fill(nrOfWorkers)(actorOf[AkkaWorkerFT].start()); val router = Routing.loadBalancerActor(SmallestMailboxFirstIterator(workers)).start() </code></pre> <p>And this is how I shut everything down:</p> <pre><code>futures.foreach( _.await ) router ! Broadcast(PoisonPill) router ! PoisonPill </code></pre> <p>Now what happens is if I send the workers messages with n > 0 (no exception is thrown), everything works fine and the application shuts down properly. However, as soon as I send it a single message which results in an exception, the application does not terminate because there is still an actor running, but I can't figure out where it comes from.</p> <p>In case it helps, this is the stack of the thread in question:</p> <pre><code> Thread [akka:event-driven:dispatcher:event:handler-6] (Suspended) Unsafe.park(boolean, long) line: not available [native method] LockSupport.park(Object) line: 158 AbstractQueuedSynchronizer$ConditionObject.await() line: 1987 LinkedBlockingQueue&lt;E&gt;.take() line: 399 ThreadPoolExecutor.getTask() line: 947 ThreadPoolExecutor$Worker.run() line: 907 MonitorableThread(Thread).run() line: 680 MonitorableThread.run() line: 182 </code></pre> <p>PS: The thread which is not terminating isn't any of the worker threads, because I've added a postStop callback, every one of them stops properly.</p> <p>PPS: <code>Actors.registry.shutdownAll</code> workarounds the problem, but I think shutdownAll should only be used as a last resort, shouldn't it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload