(counted-thread-factory name-format daemon)
Create a ThreadFactory that maintains a counter for naming Threads.
name-format specifies thread names - use %d to include counter
daemon is a flag for whether threads are daemons or not
Source
(defn counted-thread-factory
"Create a ThreadFactory that maintains a counter for naming Threads.
name-format specifies thread names - use %d to include counter
daemon is a flag for whether threads are daemons or not"
[name-format daemon]
(let [counter (atom 0)]
(reify
ThreadFactory
(newThread [this runnable]
(doto (Thread. runnable)
(.setName (format name-format (swap! counter inc)))
(.setDaemon daemon))))))