Skip to content

Instantly share code, notes, and snippets.

@bbrowning
Last active December 15, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbrowning/5311774 to your computer and use it in GitHub Desktop.
Save bbrowning/5311774 to your computer and use it in GitHub Desktop.
require 'erb'
NUM_THREADS = 400
puts "Thread with string"
threads = NUM_THREADS.times.map {
Thread.new do
'1'
end
}
threads.each(&:join)
puts "Thread with ERB"
threads = NUM_THREADS.times.map {
Thread.new do
ERB.new('1').result
end
}
threads.each(&:join)
bbrowning@bbrowning-mbp:~/tmp$ jruby -v
jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.8.0-ea-b74 +indy [darwin-x86_64]
bbrowning@bbrowning-mbp:~/tmp$ jruby erb_concurrency_test.rb
Thread with string
Thread with ERB
Exception in thread "RubyThread-724: erb_concurrency_test.rb:1" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.jruby.RubyString.cat(RubyString.java:1419)
at org.jruby.RubyString.cat19(RubyString.java:1324)
at org.jruby.RubyString.cat19(RubyString.java:1317)
at org.jruby.RubyString.append19(RubyString.java:2580)
at org.jruby.RubyString.concat19(RubyString.java:2611)
at org.jruby.RubyString$INVOKER$i$1$0$concat19.call(RubyString$INVOKER$i$1$0$concat19.gen)
at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326)
at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
at org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at org.jruby.ast.RootNode.interpret(RootNode.java:129)
at org.jruby.evaluator.ASTInterpreter.INTERPRET_EVAL(ASTInterpreter.java:96)
at org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:175)
at org.jruby.RubyKernel.evalCommon(RubyKernel.java:1103)
at org.jruby.RubyKernel.eval19(RubyKernel.java:1066)
at rubyjit.ERB$$result_DB39BCF7DCAE0101E3C2162508E49164D98727E2178030112.__file__(/Users/bbrowning/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/erb.rb:838)
at rubyjit.ERB$$result_DB39BCF7DCAE0101E3C2162508E49164D98727E2178030112.__file__(/Users/bbrowning/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/erb.rb)
at org.jruby.ast.executable.AbstractScript.__file__(AbstractScript.java:38)
at org.jruby.internal.runtime.methods.JittedMethod.call(JittedMethod.java:141)
at erb_concurrency_test.block_3$RUBY$__file__(erb_concurrency_test.rb:16)
at erb_concurrency_test$block_3$RUBY$__file__.call(erb_concurrency_test$block_3$RUBY$__file__)
at org.jruby.runtime.CompiledBlock19.yield(CompiledBlock19.java:163)
at org.jruby.runtime.CompiledBlock19.call(CompiledBlock19.java:91)
at org.jruby.runtime.Block.call(Block.java:89)
at org.jruby.RubyProc.call(RubyProc.java:261)
at org.jruby.RubyProc.call(RubyProc.java:213)
at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:98)
at java.lang.Thread.run(Thread.java:722)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment