Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow for the thread pool to use daemon threads. #20

Merged
merged 2 commits into from

2 participants

@jjcomer

I ran into a the situation where I wanted my application to quit when it could not bind to the specified port. By using daemon threads this will now happen. I have included test to verify the setting (or not setting) of the daemon threads.

@weavejester
Owner

Thanks for the changes, and thanks for sending out a new pull request after I messed up the old one :)

@weavejester weavejester merged commit b1743fc into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 29, 2012
  1. @jjcomer

    Added the option to use daemon threads in the pool

    Josh Comer authored jjcomer committed
  2. @jjcomer
This page is out of date. Refresh to see the latest.
View
8 ring-jetty-adapter/src/ring/adapter/jetty.clj
@@ -66,6 +66,7 @@
:port - the port to listen on (defaults to 80)
:host - the hostname to listen on
:join? - blocks the thread until server ends (defaults to true)
+ :daemon? - use daemon threads (defaults to false)
:ssl? - allow connections over HTTPS
:ssl-port - the SSL port to listen on (defaults to 443, implies :ssl?)
:keystore - the keystore to use for SSL connections
@@ -76,10 +77,13 @@
:client-auth - SSL client certificate authenticate, may be set to :need,
:want or :none (defaults to :none)"
[handler options]
- (let [^Server s (create-server (dissoc options :configurator))]
+ (let [^Server s (create-server (dissoc options :configurator))
+ ^QueuedThreadPool p (QueuedThreadPool. (options :max-threads 50))]
+ (when (:daemon? options false)
+ (.setDaemon p true))
(doto s
(.setHandler (proxy-handler handler))
- (.setThreadPool (QueuedThreadPool. (options :max-threads 50))))
+ (.setThreadPool p))
(when-let [configurator (:configurator options)]
(configurator s))
(.start s)
View
16 ring-jetty-adapter/test/ring/adapter/test/jetty.clj
@@ -42,7 +42,7 @@
(is (= (:body response) "Hello World")))))
(testing "configurator set to run last"
- (let [max-threads 20
+ (let [max-threads 20
new-handler (proxy [AbstractHandler] []
(handle [_ ^Request base-request request response]))
threadPool (QueuedThreadPool. ({} :max-threads max-threads))
@@ -56,6 +56,20 @@
(is (= 1 (count (.getHandlers server))))
(.stop server)))
+ (testing "setting daemon threads"
+ (testing "default (daemon off)"
+ (let [server (run-jetty hello-world {:port 4347 :join? false})]
+ (is (not (.. server getThreadPool isDaemon)))
+ (.stop server)))
+ (testing "daemon on"
+ (let [server (run-jetty hello-world {:port 4347 :join? false :daemon? true})]
+ (is (.. server getThreadPool isDaemon))
+ (.stop server)))
+ (testing "daemon off"
+ (let [server (run-jetty hello-world {:port 4347 :join? false :daemon? false})]
+ (is (not (.. server getThreadPool isDaemon)))
+ (.stop server))))
+
(testing "default character encoding"
(with-server (content-type-handler "text/plain") {:port 4347}
(let [response (http/get "http://localhost:4347")]
Something went wrong with that request. Please try again.