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

夙愿已清 提交于 2019-12-19 05:15:10

问题


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


回答1:


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.




回答2:


If you're feeling frisky, you could hack the Clojure source and rebuild (it's easy to rebuild the Clojure source). Transaction retries happen in src/jvm/clojure/lang/LockingTransaction.java in the run() method. There's a big for loop there that goes until done or RETRY_LIMIT. The value of i when the loop exits should be the retry count.




回答3:


There is STM-stress test written by Chris Houser which could be useful



来源:https://stackoverflow.com/questions/4792197/how-can-i-see-the-number-of-rollbacks-in-my-stm-in-clojure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!