Skip to content

Instantly share code, notes, and snippets.

@tggreene
Created May 4, 2020 11:16
Show Gist options
  • Save tggreene/ed7158c9a66ab8eab3e4d5d7c09bbf51 to your computer and use it in GitHub Desktop.
Save tggreene/ed7158c9a66ab8eab3e4d5d7c09bbf51 to your computer and use it in GitHub Desktop.
Get a thread by name in clojure
(defn get-thread-by-name
[thread-name]
(let [threads (keys (Thread/getAllStackTraces))]
(->> threads
(filter #(= thread-name (.getName %)))
(some identity))))
;; You can then use the value to stop the thread:
(.stop (get-thread-by-name "server-loop"))
;; Or just get more information
(bean (get-thread-by-name "clojure-agent-send-off-pool-1"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment