Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6804035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:25:02+00:00 2026-05-26T19:25:02+00:00

I am currently trying to get started with Akka and I am facing a

  • 0

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:

class AkkaWorkerFT extends Actor {
  def receive = {
    case Work(n, c) if n < 0 => throw new Exception("Negative number")
    case Work(n, c) => self reply n.isProbablePrime(c);
  }
}

And this is how I start my workers:

val workers = Vector.fill(nrOfWorkers)(actorOf[AkkaWorkerFT].start());
val router = Routing.loadBalancerActor(SmallestMailboxFirstIterator(workers)).start()

And this is how I shut everything down:

futures.foreach( _.await )
router ! Broadcast(PoisonPill)
router ! PoisonPill

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.

In case it helps, this is the stack of the thread in question:

  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<E>.take() line: 399 
    ThreadPoolExecutor.getTask() line: 947  
    ThreadPoolExecutor$Worker.run() line: 907   
    MonitorableThread(Thread).run() line: 680   
    MonitorableThread.run() line: 182   

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.

PPS: Actors.registry.shutdownAll workarounds the problem, but I think shutdownAll should only be used as a last resort, shouldn’t it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:25:02+00:00Added an answer on May 26, 2026 at 7:25 pm

    The proper way to handle problems inside akka actors is not to throw an exception but rather to set supervisor hierarchies

    “Throwing an exception in concurrent code (let’s assume we are using
    non-linked actors), will just simply blow up the thread that currently
    executes the actor.

    There is no way to find out that things went wrong (apart from
    inspecting the stack trace).
    There is nothing you can do about it.”

    see Fault Tolerance Through Supervisor Hierarchies (1.2)

    * note * the above is true for old versions of Akka (1.2)
    In newer versions (e.g. 2.2) you’d still set a supervisor hierarchy but it will trap Exceptions thrown by child processes. e.g.

    class Child extends Actor {
        var state = 0
        def receive = {
          case ex: Exception ⇒ throw ex
          case x: Int        ⇒ state = x
          case "get"         ⇒ sender ! state
        }
      }
    

    and in the supervisor:

    class Supervisor extends Actor {
        import akka.actor.OneForOneStrategy
        import akka.actor.SupervisorStrategy._
        import scala.concurrent.duration._
    
        override val supervisorStrategy =
          OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
            case _: ArithmeticException      ⇒ Resume
            case _: NullPointerException     ⇒ Restart
            case _: IllegalArgumentException ⇒ Stop
            case _: Exception                ⇒ Escalate
          }
    
        def receive = {
          case p: Props ⇒ sender ! context.actorOf(p)
        }
      }
    

    see Fault Tolerance Through Supervisor Hierarchies (2.2)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to get a script to write output from other started
I'm currently trying to get this image-map to work: <img src=products1.png usemap=products1-map style=margin-bottom: 36px
I'm currently trying to get a jQuery slider to use the percentage height of
I'm currently trying to get into the Java EE development with the Spring framework.
I'm currently trying to get the output of an executable console-app into an other
I am currently trying to get data out of a plist. It basically looks
I'm currently trying to get a grip on Android development and working my way
i am currently trying to get Input Mode Editor (IME) support working with a
I am currently trying to get my server to create a connection with a
I'm currently trying to get ActiveAdmin to work on a model of mine but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.