Yeah, I'm helping you because I have been in your shoes where legacy code 
cannot be just deleted, I'll guess you are the new guy that can't change 
things drastically...

The problem you are facing is complex and simple at the same time, you have 
Tomcat as container and Spring as DI so questions:

   - What do you need Tomcat for?
   - What do you need Spring for?
   - Spray client in Scala on top of Tomcat, why?
   - And finally, what are you using Akka for?

Now you need to think of the life cycle which Servlet 3.0 has one you can 
use:

*Context created method:* start your Spring context.
*Context destroyed method:* stop your Spring context.

When you stop Spring, it will stop all beans running in it if they have 
defined a destroy method, the destroy method needs to be declared for beans 
that need some sort of resources clean up like data sources, actor systems, 
thread pools, etc etc.

HTH

On Wednesday, June 10, 2015 at 6:23:47 PM UTC+1, Brian Topping wrote:
>
> I'm going to guess you don't find solutions because this is about the 
> point of discovery that most people dump these mixed environments. Probably 
> not what you want to hear, but not saying anything is just as bad.
>
> It's death by a thousand cuts. It all works in the large, but the cost of 
> these smaller issues doesn't necessarily have the payback you might 
> initially imagine. Since you're one of a likely small group of people doing 
> these things, there's simply a lot fewer people that can help you, 
> including running it in large deployments that resolve corner cases before 
> you get your own code into critical production requirements.
>
> It's a tale of caution, that's all.
>
> On Jun 10, 2015, at 10:11 AM, Maatary Okouya <maatar...@gmail.com 
> <javascript:>> wrote:
>
> I am using spray client i.e. akka within a Tomcat webApp.
>
> While I do properly destroy the actor system on tomcat shutdown via 
> spring, i'm nevertheless still facing this threading issue.
>
> I found that this issue was already reported few years ago Tomcat 
> complaints when re-deploying servlet with akka inside 
> <https://www.assembla.com/spaces/akka/tickets/2672#/activity/ticket:>, 
> but could not find the solution for it
>
> I'm using the default spray-client configuration.
>
> here is the error that i get when i stop tomcat. (Sorry for the amount of 
> information but i try to give as much clue as possible)
>
> 10-Jun-2015 12:54:22.516 WARNING [localhost-startStop-1] 
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The 
> web application [ROOT] appears to have started a thread named 
> [PoolPartyConnector-ActorSystem-scheduler-1] but has failed to stop it. 
> This is very likely to create a memory leak.
>
> Stack trace of thread: java.lang.Thread.sleep(Native Method) 
> akka.actor.LightArrayRevolverScheduler.waitNanos(Scheduler.scala:226) 
> akka.actor.LightArrayRevolverScheduler$$anon$8.nextTick(Scheduler.scala:405) 
> akka.actor.LightArrayRevolverScheduler$$anon$8.run(Scheduler.scala:375) 
> java.lang.Thread.run(Thread.java:745)
>
> 10-Jun-2015 12:54:22.516 WARNING [localhost-startStop-1] 
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The 
> web application [ROOT] appears to have started a thread named 
> [PoolPartyConnector-ActorSystem-akka.actor.default-dispatcher-2] but has 
> failed to stop it. This is very likely to create a memory leak. Stack trace 
> of thread: sun.misc.Unsafe.park(Native Method) 
> scala.concurrent.forkjoin.ForkJoinPool.scan(ForkJoinPool.java:2075) 
> scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) 
> scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
>
> 10-Jun-2015 12:54:22.516 WARNING [localhost-startStop-1] 
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The 
> web application [ROOT] appears to have started a thread named 
> [PoolPartyConnector-ActorSystem-akka.actor.default-dispatcher-3] but has 
> failed to stop it. This is very likely to create a memory leak. Stack trace 
> of thread: 
> akka.actor.dungeon.DeathWatch$class.watchingContains(DeathWatch.scala:73) 
> akka.actor.dungeon.DeathWatch$class.watchedActorTerminated(DeathWatch.scala:54)
>  
> akka.actor.ActorCell.watchedActorTerminated(ActorCell.scala:369) 
> akka.actor.ActorCell.invokeAll$1(ActorCell.scala:455) 
> akka.actor.ActorCell.systemInvoke(ActorCell.scala:478) 
> akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:263) 
> akka.dispatch.Mailbox.processMailbox(Mailbox.scala:241) 
> akka.dispatch.Mailbox.run(Mailbox.scala:220) 
> akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397)
>  
> scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) 
> scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
>  
> scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) 
> scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
>
> 10-Jun-2015 12:54:22.517 WARNING [localhost-startStop-1] 
> org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The 
> web application [ROOT] appears to have started a thread named 
> [PoolPartyConnector-ActorSystem-akka.actor.default-dispatcher-4] but has 
> failed to stop it. This is very likely to create a memory leak. Stack trace 
> of thread: sun.misc.Unsafe.park(Native Method) 
> scala.concurrent.forkjoin.ForkJoinPool.scan(ForkJoinPool.java:2075) 
> scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) 
> scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
>
> Another part of the trace says:
>
> 10-Jun-2015 12:54:22.571 SEVERE [localhost-startStop-1] 
> org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks 
> The web application [oai] created a ThreadLocal with key of type 
> [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@14483049]) and a 
> value of type [scala.concurrent.forkjoin.ForkJoinPool.Submitter] (value 
> [scala.concurrent.forkjoin.ForkJoinPool$Submitter@752622d4]) 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.
>
> 10-Jun-2015 12:54:22.571 SEVERE [localhost-startStop-1]
>
> org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks 
> The web application [oai] created a ThreadLocal with key of type 
> [scala.concurrent.forkjoin.ThreadLocalRandom$1] (value 
> [scala.concurrent.forkjoin.ThreadLocalRandom$1@20399e41]) and a value of 
> type [scala.concurrent.forkjoin.ThreadLocalRandom] (value 
> [scala.concurrent.forkjoin.ThreadLocalRandom@1286565]) 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.
>
> 10-Jun-2015 12:54:22.571 SEVERE [localhost-startStop-1] 
> org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks 
> The web application [oai] created a ThreadLocal with key of type 
> [scala.util.DynamicVariable$$anon$1] (value 
> [scala.util.DynamicVariable$$anon$1@64b67887]) and a value of type 
> [org.apache.tomcat.util.log.SystemLogHandler] (value 
> [org.apache.tomcat.util.log.SystemLogHandler@523e426f]) 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.
>
> 10-Jun-2015 12:54:22.571 SEVERE [localhost-startStop-1] 
> org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks 
> The web application [oai] created a ThreadLocal with key of type 
> [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@14483049]) and a 
> value of type [scala.concurrent.forkjoin.ForkJoinPool.Submitter] (value 
> [scala.concurrent.forkjoin.ForkJoinPool$Submitter@20c2d647]) 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.
>
> Finally toward the end i get the following
>
> 10-Jun-2015 12:54:22.574 INFO 
> [PoolPartyConnector-ActorSystem-akka.actor.default-dispatcher-2] 
> org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading 
> Illegal access: this web application instance has been stopped already. 
> Could not load [scala.util.control.NonFatal$]. The following stack trace is 
> thrown for debugging purposes as well as to attempt to terminate the thread 
> which caused the illegal access. java.lang.IllegalStateException: Illegal 
> access: this web application instance has been stopped already. Could not 
> load [scala.util.control.NonFatal$]. The following stack trace is thrown 
> for debugging purposes as well as to attempt to terminate the thread which 
> caused the illegal access. at 
> org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1327)
>  
> at 
> org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1313)
>  
> at 
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1196)
>  
> at 
> org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
>  
> at 
> akka.actor.ActorSystemImpl$$anon$2.uncaughtException(ActorSystem.scala:511) 
> at 
> akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:405)
>  
> at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at 
> scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
>  
> at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) 
> at 
> scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
>
>
> PS: 
>
> This is causing an issue in my Intellij. Indeed, i can still start and 
> stop from the terminal tomcat. However, from within Intellij I get the 
> following on restart: 
>
> *Error: Exception thrown by the agent : java.rmi.server.ExportException: 
> Port already in use: 1099; nested exception is: *
> * java.net.BindException: Address already in use *
>
> *I have to kill the process on 1099 every time to restart from within 
> intellij.*
>
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: 
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+...@googlegroups.com <javascript:>.
> To post to this group, send email to akka...@googlegroups.com 
> <javascript:>.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to