Forum: JRuby Starting a thread from Glassfish

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
22785d4dbf585723bf60458ece0170e1?d=identicon&s=25 Joseph Athman (Guest)
on 2009-04-30 04:55
(Received via mailing list)
I'm working on a project that is looking in to using the glassfish gem
for
our Rails application.  One thing we need to do with this application is
have a process/thread running which is periodically (e.g. once per
second)
communicate with an external device.  What I was thinking we could do is
start up a normal ruby thread inside of a Rails initializer, but the
problem
I'm finding is that glassfish will start up multiple Rails runtimes
which
are each starting up their own background thread.  Anyone have any ideas
on
a way to start up only one thread no matter how many rails runtimes spin
up?

Joe
08264fc914cfb45adfea6c2f36f70b21?d=identicon&s=25 Jacob Kessler (Guest)
on 2009-04-30 18:36
(Received via mailing list)
The obvious way, if you can, is to run Rails in thread-safe mode.
GlassFish Gem will only start up one instance of rails if Rails is in
thread-safe mode. If you only need one runtime, you can also run with
--runtimes-max 1, which will limit it to a single runtime. However,
limiting it to a single runtime without thread-safe mode will prevent
serving concurrent requests.

Failing that, you would want to put a check into the thread starting
code to check to see if the thread has already started. Though I'm not
sure how to do that in Ruby, I'd guess that either checking for a named
thread before creating your own or touching a file on disk that you can
check would work.

Joseph Athman wrote:
> Joe
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
22785d4dbf585723bf60458ece0170e1?d=identicon&s=25 Joseph Athman (Guest)
on 2009-04-30 18:52
(Received via mailing list)
That's what's weird, I set up Rails to run in thread-safe mode, and only
use
1 rails instance, but I swear that all of my Rails initializers are
being
run twice.  I have a lot of constants set up in initializers and with
GlassFish I get a bunch of ruby warnings about constants already being
defined.  This does not happen with Mongrel.  If GF is starting more
than
one rails runtime would I get those already initialized constant
warnings?
I'm not totally sure if GF starts one JRuby runtime but 2 rails
runtimes, or
if it would be 2 JRuby runtimes and 2 rails instances.  Anyone know?

Joe
08264fc914cfb45adfea6c2f36f70b21?d=identicon&s=25 Jacob Kessler (Guest)
on 2009-04-30 19:11
(Received via mailing list)
There was a bug for this, since we were initializing Rails incorrectly
(loading things twice). I can't find the report now, but it has since
been fixed. It will run the initializers twice, but only one rails
instance will come up. Since starting multiple Rails instances always
happens in separate JRuby runtimes, you won't (or shouldn't) see those
warnings if you were starting multiple runtimes.

For now, you may be able to ignore those warnings, but I'll pester Vivek
to release a new version of the gem with that fix in it.

Joseph Athman wrote:
> Joe
>
>         glassfish gem for our Rails application.  One thing we need to
>
>
>
>     ---------------------------------------------------------------------
>     To unsubscribe from this list, please visit:
>
>       http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
22785d4dbf585723bf60458ece0170e1?d=identicon&s=25 Joseph Athman (Guest)
on 2009-04-30 19:17
(Received via mailing list)
Thank you very much, this answers a lot of my questions.  Should this
bug be
fixed in the currently released GF gem?  I think I'm on the latest one
available.

Joe
This topic is locked and can not be replied to.