I'm developing a Servlet-based web application in Scala, and using Akka. Everything works fine while it's up and running, I see no errors when viewing code, my child actors all bring themselves up and shut themselves down correctly. However; when I try to shut down my server, or re-deploy I get a lot of errors in the console:
Shutting down...
Shut down successfully.
27-Mar-2015 11:21:22.233 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@68d6d1aa]) and a value of type [scala.concurrent.forkjoin.ForkJoinPool.Submitter] (value [scala.concurrent.forkjoin.ForkJoinPool$Submitter@1045f98]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
27-Mar-2015 11:21:22.233 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [scala.util.DynamicVariable$$anon$1] (value [scala.util.DynamicVariable$$anon$1@5f818593]) and a value of type [org.apache.tomcat.util.log.SystemLogHandler] (value [org.apache.tomcat.util.log.SystemLogHandler@5b616a23]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
27-Mar-2015 11:21:22.241 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
27-Mar-2015 11:21:22.243 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
27-Mar-2015 11:21:22.244 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
27-Mar-2015 11:21:22.244 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
Disconnected from server
If I try use a regular, synchronous servlet I don't get the messages in the log upon shutdown.
I have a context listener on the servlet which is the following:
class ContextListener extends ServletContextListener {
private var system: ActorSystem = _
override def contextInitialized(sce: ServletContextEvent): Unit = {
val context = sce.getServletContext
system = ActorSystem.create("StridentStandard")
context.setAttribute("actor.system", system)
}
override def contextDestroyed(sce: ServletContextEvent): Unit = {
println("Shutting down...")
system.shutdown()
system.awaitTermination()
println("Shut down successfully.")
}
}
So, from what it looks like - the ActorSystem should be shutting down correctly - but it seems some threads are hanging on.
I'm fairly new to Scala, and Akka... and concurrency, and as a result am not really sure where to go from here.