I\'ve read a lot about how great Clojure is when it comes to concurrency, but none of the tutorials I\'ve read actually explain how to create a thread. Do you just do (.start (T
The (future f)
macro wraps the form f in a Callable (via fn*) and submits that to a thread pool immediately.
if you need a reference to a java.lang.Thread object, for instance, to use it as a java.lang.Runtime shutdown hook, you can create a Thread like this:
(proxy [Thread] [] (run [] (println "running")))
This will not start the thread yet, only create it. To create and run the thread, submit it to a thread pool or call .start on it:
(->
(proxy [Thread] [] (run [] (println "running")))
(.start))
Brians's answer also creates a thread but doesn't need proxy, so that's very elegant. On the other hand, by using proxy we can avoid creating a Callable.