Absolutly, Clojure embraces its host platform. Always feel free to use the Java features when they work best for your use case.
But just to clarify, Java's ThreadLocal is an implementation of dynamic scoping. The scope is determined not by the source code, but by the runtime circumstances, in this case, the running Thread. While it's not the classic kind of dynamic scoping, it is still dynamic and not lexical. It differs from Clojure's dynamic scope in that, Clojure's scope is determined by the runtime stack plus the current thread. Clojure relies on ThreadLocal for the per-thread scoping implementation, and it uses its own implementation for the runtime stack based scoping. This means that if you want to re-enter a thread after having executed in its context before, and still have access to its previously bound ThreadLocal, you can only do it with a ThreadLocal. With Clojure's dynamic Vars, I don't think this is possible, since Clojure restores the previous binding when you exit from the thread. Now, be careful with this, I've seen lots of bugs in Java due to people not realizing that the binding is permanently attached to the thread, unless explicitly unbound, especially with the use of thread pools. So I'd consider Clojure dynamic Vars safer to use in most cases, and still would recommend you use them instead of ThreadLocal most of the time. Unless what you want to do is attach state to the thread, dynamic Vars will probably be better and easier. Just my 2 cents. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.