(defn exit [status]
(shutdown-agents)
(flush)
(System/exit status))
Yet, despite this, the JVM never exits. Here is a snippet of jstack
output:
--8<---------------cut here---------------start------------->8---
"DestroyJavaVM" prio=10 tid=0x00000000406c7c00 nid=0x445d waiting on condition [0x0000000000000000..0x0000000041e48d10]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"pool-1-thread-10" prio=10 tid=0x00007fd9744fac00 nid=0x447c waiting on condition [0x0000000042e58000..0x0000000042e58da0]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00007fd981140198> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:358)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
--8<---------------cut here---------------end--------------->8---
What else can I try to force everything to shut down?
Thanks!
-Drew
> I believe this is an issue related to how the threadpools used by
> executors are populated by default, i.e. they use non-daemon
> threads.
>
> clojure.lang.Agent uses instances of these default threadpool
> configurations, which is likely the cause of the delayed shutdown
> of the JVM (I'll bet that if you let the process linger for a
> couple minutes, the threadpools' timeouts will trip, the non-daemon
> threads will die, and the process will exit gracefully).
Oddly enough, this is the behavior I generally see interactively.
When spawned via cron(8), however, the java processes linger for
weeks and I have to manually kill(1) them.
Is there something in that execution environment that would suppress
the threadpool timeout?
-Drew
> I think you are responsible for ending the currently running
> agents. The usual method is to set up some field which the agents
> monitor looking for some value indicating the application is
> ending.
By "ending currently running agents" do you mean the action run on
the agent? My problem doesn't seem to be action-related because when
I take out the agents and execute the same code synchronously, the
JVM exits as I expect.
For the record, I was able to consistently hang the JVM indefinitely
from the command line in addition to invocation from cron, contrary
to my claim in my other message. I suspect that others are not
seeing any issues because most Java environments are persistent.
Anyone else scripting with Clojure using agents?
Thanks.
-Drew