1

I am using Clojure's core.async in a servlet program. I am suspecting a memory leak in the program and I recognized that the total number of alive threads does not decrease when I undeploy my application from the application server (Glassfish).

My question is: how can I clean up the unused core.async threads when I undeploy my application?

I understand that core.async manages its own thread pools:

  1. It uses a cached thread pool for running (thread) macros. The threads in the pool get cleaned up automatically after 60 seconds of inactivity according to the docs.
  2. However, it uses a fixed thread pool for running workers. An explicit shutdown should have been called to stop this thread pool, but the thread pool implementation is not publicly visible.

What is a nice way to shut down core.async when undeploying an application?

erdos
  • 3,135
  • 2
  • 16
  • 27
  • The function shutdown-agents shuts down an other thread pool unrelated to core.async. I use that too but the core.async threads are still kept alive. They are in a different executor service. – erdos Dec 14 '18 at 05:59
  • How about [stopping the whole executor altogether](https://stackoverflow.com/questions/1562079/how-to-stop-the-execution-of-executor-threadpool-in-java)? – akond Dec 14 '18 at 08:58
  • this is exactly what i want to do. however, you see, i need a publicly accessible reference to the executor instance to call `.shutdown` which is not available. – erdos Dec 14 '18 at 09:14
  • Oh, I see now. `executor-svc` is closed as a local variable inside `thread-pool-executor`? – akond Dec 14 '18 at 09:22
  • exactly! i wonder if there are any other ways in the jvm to shut down an executor service (and how to locate the one i need) – erdos Dec 14 '18 at 09:25
  • I think it is time for you to go to #core-async slack channel. – akond Dec 14 '18 at 09:29

0 Answers0