From 3bd12a6c50c51b5d8b8ac821af66a0bf1bd5d46f Mon Sep 17 00:00:00 2001 From: Ryan Fowler Date: Mon, 14 Dec 2015 10:51:41 -0600 Subject: [PATCH] Use java.util.concurrent.ExecutorService/submit instead of `future` (future) starts the agent threadpool, which slows down shutdown unless (shutdown-agents) is called. --- src/taoensso/timbre.cljx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/taoensso/timbre.cljx b/src/taoensso/timbre.cljx index d8cd688f..d04ee028 100644 --- a/src/taoensso/timbre.cljx +++ b/src/taoensso/timbre.cljx @@ -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))