In my project many clients will modify a map in server. I use a ref of map, like this:
(def dict (ref {})) ; the map we play with
And I update this map using dosync, the STM way. But I found it not as fast as I wish:
user=> (time (dotimes [n 1000000] (dosync ( alter xx assoc xx 1 1))))
"Elapsed time: 2470.766 msecs"
So I decide to use native Java CuncurrentHashMap to take the place of Clojure build-in map and STM. How can I wrap Java CuncurrentHashMap into Clojure so that i can modify it like Clojure map, using assoc, contains?, dissoc and so on. This will make me modify lest line of code.
Is there a way to achieve this?
You can use
atom, as you are only modifying a single value you don’t need a transaction and hence no need forref