JRuby/Rufus-Scheduler/Tomcat threading problem

90 views
Skip to first unread message

Matt P

unread,
Oct 7, 2008, 5:21:00 PM10/7/08
to Rufus Ruby
Hi -

This question may be more suited for a Tomcat forum, but since I am
getting a scheduler specific exception, I thought I would try here
first.

JRuby on Rails (2.1.1), rufus-scheduler (1.0.11), Tomcat (6.0.18)

I have successfully deployed a JRuby app to Tomcat that starts a new
thread, here is the code:

Thread.new {

scheduler = Rufus::Scheduler.start_new

scheduler.cron "0 2 * * *", :tags => "sov" do
sov = SovResults.new
sov.process
end

ActiveRecord::Base.verify_active_connections!()
}

This works well. However, the next time I deploy, I get an exception
in catalina.out after Tomcat undeploys my original app and the Thread
is still alive and tries to access the environment, but it's been
undeployed. See stack below. The new app deploys, but the old thread
is still out there. Looks like the unschedule method fails because it
can't find the app. So I end up with old threads hanging out there.
Only solution is to restart tomcat, which isn't a great solution. Is
there anyway to force this thread to die?


Oct 7, 2008 2:25:24 PM org.apache.catalina.loader.WebappClassLoader
loadClass
INFO: Illegal access: this web application instance has been stopped
already. Could not load org.jruby.runtime.Frame$1. The eventual
following stack trace is caused by an error thrown for debugging
purposes as well as to attempt to terminate the thread which caused
the illegal access, and has no functional impact.
java.lang.IllegalStateException
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1273)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1233)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:
319)
at org.jruby.runtime.Frame
$BackrefAndLastline.<init>(Frame.java:92)
at org.jruby.runtime.Frame.lazyBackrefAndLastline(Frame.java:
343)
at org.jruby.runtime.Frame.<init>(Frame.java:133)
at org.jruby.runtime.Frame.duplicate(Frame.java:250)
at org.jruby.runtime.Binding.<init>(Binding.java:63)
at
org.jruby.runtime.CompiledBlock.newCompiledClosure(CompiledBlock.java:
74)
at
org.jruby.javasupport.util.RuntimeHelpers.createBlock(RuntimeHelpers.java:
84)
at ruby.jit.ruby.***.****.*****.releases.
$20081007185354.WEB_minus_INF.gems.gems.rufus_minus_scheduler_minus_1_dot_0_dot_11.lib.rufus.scheduler.step_unschedule30681653_33198469.__file__(scheduler.rb:
897)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:
202)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.call(CallSite.java:340)
at ruby.jit.ruby.***.***.***.releases.
$20081007185354.WEB_minus_INF.gems.gems.rufus_minus_scheduler_minus_1_dot_0_dot_11.lib.rufus.scheduler.step10715419_33198469.__file__(scheduler.rb:
879)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:
202)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.call(CallSite.java:340)
at org.jruby.ast.VCallNode.interpret(VCallNode.java:82)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:
202)
at
org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:153)
at org.jruby.runtime.Block.yield(Block.java:105)
at org.jruby.RubyKernel.loop(RubyKernel.java:1039)
at org.jruby.RubyKernel$s_method_0_0$RUBYFRAMEDINVOKER
$loop.call(org/jruby/RubyKernel$s_method_0_0$RUBYFRAMEDINVOKER
$loop.gen)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.cacheAndCall(CallSite.java:144)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.callIter(CallSite.java:374)
at
org.jruby.ast.FCallNoArgBlockNode.interpret(FCallNoArgBlockNode.java:
31)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:101)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:67)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:
202)
at
org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:190)
at org.jruby.runtime.BlockBody.call(BlockBody.java:64)
at org.jruby.runtime.Block.call(Block.java:101)
at org.jruby.RubyProc.call(RubyProc.java:200)
at org.jruby.RubyProc.call(RubyProc.java:187)
at
org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:90)
at java.lang.Thread.run(Thread.java:595)

John Mettraux

unread,
Oct 7, 2008, 5:30:30 PM10/7/08
to rufus...@googlegroups.com
On Wed, Oct 8, 2008 at 6:21 AM, Matt P <mattp...@gmail.com> wrote:
>
> This question may be more suited for a Tomcat forum, but since I am
> getting a scheduler specific exception, I thought I would try here
> first.
>
> JRuby on Rails (2.1.1), rufus-scheduler (1.0.11), Tomcat (6.0.18)
>
> I have successfully deployed a JRuby app to Tomcat that starts a new
> thread, here is the code:
>
> Thread.new {
>
> scheduler = Rufus::Scheduler.start_new
>
> scheduler.cron "0 2 * * *", :tags => "sov" do
> sov = SovResults.new
> sov.process
> end
>
> ActiveRecord::Base.verify_active_connections!()
> }
>
> This works well. However, the next time I deploy, I get an exception
> in catalina.out after Tomcat undeploys my original app and the Thread
> is still alive and tries to access the environment, but it's been
> undeployed. See stack below. The new app deploys, but the old thread
> is still out there. Looks like the unschedule method fails because it
> can't find the app. So I end up with old threads hanging out there.
> Only solution is to restart tomcat, which isn't a great solution. Is
> there anyway to force this thread to die?

Hello Matt,

at first a question : why do you start the scheduler in a thread ? You
could simply start it from the current thread, keep a reference to it
and make sure that tomcat, when undeploying, stops the current
scheduler.

(I can't remember where the hook for that is in Tomcat).

I guess you could do the verify_active_connections() in the scheduling
block or directly in the process method of your SovResult class.

When you start the Scheduler, it has its own thread, no need for
another one usually.


Hope this will help, best regards,

--
John Mettraux - http://jmettraux.wordpress.com

Matt P

unread,
Oct 8, 2008, 12:08:43 PM10/8/08
to Rufus Ruby
Thanks for the thread tip on the scheduler. I don't know how I missed
that. I'm still looking into the Tomcat part of it hanging onto the
JRuby threads. I don't believe it is in the scheduler, but thought I
would get some thoughts if anyone had any experience. Thanks again.

On Oct 7, 4:30 pm, "John Mettraux" <jmettr...@openwfe.org> wrote:
Reply all
Reply to author
Forward
0 new messages