Search code examples
javamultithreadingclojurethread-localthread-local-storage

thread local variables in clojure


  1. For no other reason than i have a lot of other custom libraries that i have written that run on 1.1.

I need a straight forward way to have thread local variables a lot of the method i have seen are incompatible with this version of clojure.

seen in this examples

e.g. (thread-local (atom 0)))

(def ^{:dynamic true} counter)

don't seem to work for me

So i just need to be pointed in the right direction.


Solution

  • There's a class for that!

    user=> (def local (ThreadLocal.))
    #'user/local
    user=> (.set local 3)
    nil
    user=> (.get local)
    3