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
Yes, the way that you start a Java Thread in Clojure is something like what you have there.
However, the real question is: why would you want to do that? Clojure has much better concurrency constructs than threads.
If you look at the canonical concurrency example in Clojure, Rich Hickey's ant colony simulation, you will see that is uses exactly 0 threads. The only reference to java.lang.Thread
in the entire source is three calls to Thread.sleep
, whose sole purpose is to slow the simulation down so that you can actually see what is going on in the UI.
All the logic is done in Agents: one agent for every ant, one agent for the animation and one agent for the pheromone evaporation. The playing field is a transactional ref. Not a thread nor lock in sight.