[#141] Use java.util.concurrent.ExecutorService/submit instead of `future` (@ryfow)

(future) starts the agent threadpool, which slows down shutdown unless
(shutdown-agents) is called.
This commit is contained in:
Ryan Fowler 2015-12-14 10:51:41 -06:00 committed by Peter Taoussanis
parent ffe66948c6
commit d59d902611
1 changed files with 13 additions and 6 deletions

View File

@ -563,13 +563,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
;; 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")))]
(deref f_ 5000 "UnknownHost")))))
(catch java.net.UnknownHostException _ "UnknownHost"))))]
(try
(deref f_ 5000 "UnknownHost")
(finally (.shutdown executor)))))))
(comment (get-hostname))