clojurestm

How can I see the number of rollbacks in my STM in Clojure?


How can I see the number of rollbacks in my STM in Clojure?


Solution

  • You can't... unless you are willing to cheat:

    (defmacro spy-dosync [& body]
      `(let [retries# (atom -1)
             result# (dosync
                       (swap! retries# inc)
                       ~@body)]
         (println "retries count:" @retries#)
         result#))
    

    and then replace your dosync by a spy-dosync.