AkkaApplication: Clean way to shutdown and join
I'm thinking of something like Jetty's Server object, which supports:
With Akka right now I copied akka-kernel which does:
This seems like sort of a hack. A nicer solution could be: be able to wait until there are no actors running in the default dispatcher, then join the dispatcher's thread pool and exit cleanly. Something like:
With non-default dispatchers, this could also be used to wait for a set of actors to finish, just as you'd use awaitTermination on a thread pool.
Issue: some actors may need to be "daemon" actors (like "daemon" threads) so they don't keep the dispatcher alive.
Server server = new Server(8080);
server.start();
server.join();
With Akka right now I copied akka-kernel which does:
object Main {
val keepAlive = new CountDownLatch(2)
def main(args: Array[String]) = {
Kernel.boot
keepAlive.await
}
}
This seems like sort of a hack. A nicer solution could be: be able to wait until there are no actors running in the default dispatcher, then join the dispatcher's thread pool and exit cleanly. Something like:
Dispatchers.defaultGlobalDispatcher.join()
With non-default dispatchers, this could also be used to wait for a set of actors to finish, just as you'd use awaitTermination on a thread pool.
Issue: some actors may need to be "daemon" actors (like "daemon" threads) so they don't keep the dispatcher alive.
Leave a comment
on 2011-10-07 15:46 *
By viktorklang
Summary changed from Clean way to shutdown and join to AkkaApplication: Clean way to shutdown and join
Duplicate of 1229
Updating tickets (#1129, #1132, #1138, #1149, #1153, #1154, #1157, #1161, #1163, #1168, #1170, #1171, #1172, #1176, #1177, #1178, #1180, #1199, #1217, #1218, #1219, #1237, #1238, #1239, #1244, #1246, #1249, #1250, #1251, #1252, #1256, #1301, #1302, #1306, #1395, #1396, #1409, #1418, #455, #891, #895, #912, #956, #972, #1031, #1374, #880, #1125, #1146)