Skip to content

Commit

Permalink
Use java.util.concurrent.ExecutorService/submit instead of future
Browse files Browse the repository at this point in the history
(future) starts the agent threadpool, which slows down shutdown
unless (shutdown-agents) is called.
  • Loading branch information
ryfow committed Dec 14, 2015
1 parent afe6dd3 commit 3bd12a6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/taoensso/timbre.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,20 @@

#+clj
(def get-hostname
;; Note that this triggers slow shutdown, Ref. http://goo.gl/5hx9oK:
(enc/memoize* (enc/ms :mins 1)
(fn []
(let [f_ (future ; Android doesn't like this on the main thread
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _ "UnknownHost")))]
(deref f_ 5000 "UnknownHost")))))
(fn []
;; Android doesn't like this on the main thread
;; `future` starts the agent threadpool so we use
;; java.util.concurrent.
(let [executor (java.util.concurrent.Executors/newSingleThreadExecutor)
f_ (.submit executor
^java.util.concurrent.Callable
(fn []
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _ "UnknownHost"))))]
(try
(deref f_ 5000 "UnknownHost")
(finally (.shutdown executor)))))))

(comment (get-hostname))

Expand Down

0 comments on commit 3bd12a6

Please sign in to comment.