Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns transaction-test
- (:refer-clojure :exclude [time]))
- (def r1 (ref 0 :min-history 20))
- (def base-time (System/currentTimeMillis))
- (defn time []
- (- (System/currentTimeMillis) base-time))
- (defn retries []
- (let [count (atom 0)]
- (dosync
- (swap! count inc)
- (Thread/sleep 1000)
- (alter r1 identity))
- ;;@r1)
- ;;(ensure r1))
- (println (format "%d retries, r1=%d" @count @r1))
- (println (str "3: " (time)))))
- (println (str "1: " (time)))
- (-> retries Thread. .start)
- (dotimes [_ 4]
- (dosync
- (Thread/sleep 300)
- (alter r1 inc)))
- (println (str "2: " (time)))
- ;; Example result:
- ;; 1: 57
- ;; 2: 1309
- ;; 3 retries, r1=4
- ;; 3: 3079
Advertisement
Add Comment
Please, Sign In to add comment