Help! Consider the following naughty script:
require ‘thread’
t = Thread.new do
while (true)
puts “Still alive”
sleep 10
end
end
t.join
Obviously it will not die! Now I will run it in RedBridge (via the
variable ‘scriptlet’), consider the following irb output:
irb(main):001:0> require ‘java’
=> true
irb(main):002:0> scriptlet = “require ‘thread’;t = Thread.new do while
(true);puts “Still alive”;sleep 10 end end; t.join”
=> “require ‘thread’;t = Thread.new do while (true);puts “Still
alive”;sleep 10 end end; t.join”
irb(main):003:0> java_import ‘org.jruby.embed.ScriptingContainer’
=> Java::OrgJrubyEmbed::ScriptingContainer
irb(main):004:0> container = ScriptingContainer.new
=> #Java::OrgJrubyEmbed::ScriptingContainer:0x6cc2a4
irb(main):005:0> require ‘thread’
=> true
irb(main):006:0> Thread.new do container.runScriptlet(scriptlet) end
=> #<Thread:0x17d7c7f run>
irb(main):007:0> Still alive
irb(main):008:0* Still alive
Still alive
Still alive
irb(main):009:0* container.getProvider.getRuntime.tearDown(true)
=> nil
irb(main):010:0> Still alive
Still alive
Still alive
Still alive
Still alive
Still alive
Obviously I want a mechanism to make my container just call it quits and
‘container.getProvider.getRuntime.tearDown(true)’ is not getting it
done.
How do I do it?
Thanks,
Cris