Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Last active December 13, 2015 20:08
Show Gist options
  • Select an option

  • Save martintrojer/4967220 to your computer and use it in GitHub Desktop.

Select an option

Save martintrojer/4967220 to your computer and use it in GitHub Desktop.
ThreadPoolExecutor
(def pool (java.util.concurrent.Executors/newFixedThreadPool 2))
(def l1 (java.util.concurrent.CountDownLatch. 1))
(def l2 (java.util.concurrent.CountDownLatch. 1))
(defn worker [] (.await l1) (println "l1") (.await l2) (println "done!"))
(dotimes [_ 4] (.submit pool worker))
(.countDown l1)
;; l1
;; l1
(countDown l2)
;; done!
;; l1
;; done!
;; l1
;; don done!e!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment