Skip to content

Instantly share code, notes, and snippets.

@billdueber
Created June 24, 2011 18:57
Show Gist options
  • Save billdueber/1045423 to your computer and use it in GitHub Desktop.
Save billdueber/1045423 to your computer and use it in GitHub Desktop.
Log and inability to catch breakjump under jruby 1.6.2
require 'java'
def showBreakProblem &blk
threads = 2
consumers = []
threads.times do |i|
consumers << Thread.new(i) do |i|
Thread.current[:num] = i
begin
(1..10).each do |i|
blk.call(i)
end
rescue Exception => e
print "Got exception #{e.inspect}"
end
end
end
consumers.each {|t| t.join}
end
showBreakProblem do |i|
tnum = Thread.current[:num]
print "#{tnum}: #{i}\n"
break if tnum == 1 and i == 3
sleep 0.1
end
# OUTPUT
#
# 0: 1
# 1: 1
# 0: 2
# 1: 2
# 0: 3
# 1: 3
# Exception in thread "RubyThread-1: t2.rb:1" org.jruby.exceptions.JumpException$BreakJump
# 0: 4
# 0: 5
# 0: 6
# 0: 7
# 0: 8
# 0: 9
# 0: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment