Skip to content

Instantly share code, notes, and snippets.

@obohrer
Created January 29, 2013 09:30
Show Gist options
  • Save obohrer/4662995 to your computer and use it in GitHub Desktop.
Save obohrer/4662995 to your computer and use it in GitHub Desktop.
Concurrency test
(require '[clojure.tools.logging :as log])
(import '(java.util.concurrent Executors))
(defn t [f expected nthreads niters]
(let [pool (Executors/newFixedThreadPool nthreads)
tasks (map (fn [t]
(fn []
(dotimes [n niters]
(let [res (f)]
(when (not= res expected)
(log/info "Result is not expected : " res))))))
(range nthreads))]
(doseq [future (.invokeAll pool tasks)]
(.get future))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment