Affects Version/s: Release 1.5, Release 1.6
Fix Version/s: None
The original description when this ticket was vetted is below, starting with "Reported by cemer...@snowtide.com, June 01, 2009". This prefix attempts to summarize the issue and discussion.
Several Clojure functions involving agents and futures, such as future, pmap, clojure.java.shell/sh, and a few others, create non-daemon threads in the JVM. These can cause a 60-second wait after a Clojure program is done before the process exits. Questions about this confusing behavior come up a couple of times per year on the Clojure Google group. Search for shutdown-agents to find most of these occurrences, since calling (shutdown-agents) at the end of one's program typically eliminates this 60-second wait.
Summary of comments before July 2014:
Most of the comments on this ticket on or before August 23, 2010 were likely spread out in time before being imported from the older ticket tracking system into JIRA. Most of them refer to an older suggested patch that is not in JIRA, and compilation problems it had with JDK 1.5, which is no longer supported by Clojure 1.6.0. I think these comments can be safely ignored now.
Alex Miller blogged about this and related issues here: http://tech.puredanger.com/2010/06/08/clojure-agent-thread-pools/
Since then, two of the suggestions Alex raised have been addressed. One by
CLJ-378 and one by the addition of set-agent-send-executor! and similar functions to Clojure 1.5.0: https://github.com/clojure/clojure/blob/master/changes.md#23-clojurecoreset-agent-send-executor-set-agent-send-off-executor-and-send-via
One remaining issue is the topic of this ticket, which is how best to avoid this 60-second pause.
One method is mentioned in Chas Emerick's original description below, suggested by Rich Hickey, but perhaps long enough ago he may no longer endorse it: Create a Var *auto-shutdown-agents* that when true (the default value), clojure.lang.Agent shutdown() is called after the clojure.main entry point. This removes the surprising wait for common methods of starting Clojure, while allowing expert users to change that value to false if desired.
Another method mentioned in the discussion is to change the threads created in agent thread pools to daemon threads by default, and perhaps to deprecate shutdown-agents or modify it to be less dangerous. That approach is discussed a bit more in Alex's blog post linked above, and in a comment from Alexander Taggart on July 11, 2011 below.
The only other comment before 2014 that is not elaborated in this summary is shoover's suggestion of an alternate approach dated Aug 23 2010.
See the Jul 31 2014 comment when this patch was attached to the ticket for some description of its approach, which is an attempt to implement the *auto-shutdown-agents* method mentioned above.