JRuby中的Clojure STM
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JRuby中的Clojure STM相关的知识,希望对你有一定的参考价值。
require "java" require "clojure.jar" include_class "clojure.lang.LockingTransaction" include_class "clojure.lang.Ref" my_account = Ref.new(1) puts "Initial value #{my_account.deref}" begin my_account.set(1000) rescue java.lang.IllegalStateException puts "Reference updated outside a transaction.. Naughty.. :)" end puts "Value after failed update #{my_account.deref}" Thread.new {LockingTransaction.run_in_transaction(Proc.new { my_account.set 1000 })} Thread.new {LockingTransaction.run_in_transaction(Proc.new { sleep 0.1; my_account.set 21000 })} # Will fail because get commited after first transaction puts "Value after successful transaction #{my_account.deref}"
以上是关于JRuby中的Clojure STM的主要内容,如果未能解决你的问题,请参考以下文章
mingw / git bash shell中的jRuby问题
部署为 WAR 时 JRuby 中的线程安全 Resque Workers