Correct way to start ActorSystem with AKKA Java API

I am using Java API for Akka 2.0 and feel that I am not using ActorSystem correctly to start and / or / xor stop TypedActors. When the application is closed, the java process is not terminated. After debugging, I see that the default manager still has multiple threads running and the scheduler is still running. Is there something obvious that I am doing wrong in the example below?

Config akkaConf = ConfigFactory.load();
ActorSystem actorSystem = ActorSystem.create("myApp", akkaConf);

TypedProps<Actor1Impl> actor1TypedProps = new TypedProps<Actor1Impl>(Actor1Interface.class, new Creator<Actor1Impl>(
    public Actor1Impl create() {
        return new Actor1Impl(nonDefault, constructor, scalaIsSo, muchMoreElegant);
    }
);
Actor1Interface a1 = TypedActor.get(actorSystem).typedActorOf(actor1TypedProps, "anA1Actor");

      

Unbeknownst to the readers (and for brevity), the Actor1Impl class implements TypedActor.PreStart and .PostStop. In PreStart, it starts the Runnable task to run periodically. I thought this might keep the Scheduler active, but I also kept the returned Cancellable, which I believe should be canceled in the PostStop block. It didn't help to terminate the Scheduler thread. Anyway, back to history ...

There are also a number of other types of actors, each with a nonStandard constructor. Some of them register periodic Runnables with a scheduler like Actor1Impl above. And to add to the fun, some even require different Actors as constructor arguments so that Actors can register for callbacks, like this:

public Actor2Impl(Actor1Interface a1) {
    a1.registerCallback(TypedActor.<Actor2Interface>self());
}

      

After determining that the application has outlived its usefulness, the following is performed:

TypedActor.get(actorSystem).stop(a1);
TypedActor.get(actorSystem).stop(a2);
...
TypedActor.get(actorSystem).stop(aN);
actorSystem.shutdown();

      

Is there something I am doing that is blatantly wrong that could cause the Java process to terminate? In particular, anything that could cause the default scheduler and dispatcher to be disabled?

+3


source to share





All Articles