Forum: JRuby glassfish gem - shared singleton

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.
09ff7ecfeb4eda31899dd7b18d616bb6?d=identicon&s=25 Scott Miller (scott-a-miller)
on 2009-01-29 18:10
(Received via mailing list)
Hi Everyone,
I'm currently using the glassfish gem (0.9.1) with jruby (1.1.6) to host
a
rails application.  I'm wondering if there is a recommended/supported
way of
having a singleton shared among multiple jruby runtimes.  It appears
that
each of the runtimes has its own child class loader (which makes sense)
- so
just naively requiring the jar file causes each runtime to have it's own
instance.  Is there an easy way that I can get my singleton class loaded
into the parent class loader before the runtimes get created?

Thanks,
Scott
08264fc914cfb45adfea6c2f36f70b21?d=identicon&s=25 Jacob Kessler (Guest)
on 2009-01-29 20:14
(Received via mailing list)
Not really... However, there are a few hack-ish things that you could
try.

Given that you are using gem, you *might* be able to modify the load
script to load your jar, where it should show up in the parent
classloader. I'm not sure if that would work at all, though.

You may also be able to do something Jave EE-ish and have a singleton
bean that you could access from all of the runtimes, but that would most
likely be painful and difficult.

Another possibility would be moving to threadsafe mode in Rails 2.2,
where there would always only be a single runtime, and you could have
your singleton easily (as long as you weren't doing non-threadsafe
things with it, of course).

Scott Miller wrote:
>
> Thanks,
> Scott


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

    http://xircles.codehaus.org/manage_email
09ff7ecfeb4eda31899dd7b18d616bb6?d=identicon&s=25 Scott Miller (scott-a-miller)
on 2009-01-29 21:00
(Received via mailing list)
Thanks for the response.  That was going to be my follow up question:
how
confident are people with the new thread-safe mode?  If it's solid (in
rails
2.2.2), then I'd prefer to take that approach anyway (and save some
memory
as well).
F7e175b37a4c69709ef75c28792f2b32?d=identicon&s=25 Ikai Lan (Guest)
on 2009-01-29 22:37
(Received via mailing list)
It's solid. We're running it on our production JRuby applications at
LinkedIn.

If you use MemCache, either enable threadsafe mode in memcache-client or
use
JRuby-MemCached wrapper
(http://github.com/ikai/jruby-memcache-client/tree/master).

Ikai
F7e175b37a4c69709ef75c28792f2b32?d=identicon&s=25 Ikai Lan (Guest)
on 2009-01-29 22:39
(Received via mailing list)
I should also mention additional benefits of running a single JRuby
instance:

- we cut our memory footprint in half on each app server
- reduced startup time

Ikai
09ff7ecfeb4eda31899dd7b18d616bb6?d=identicon&s=25 Scott Miller (scott-a-miller)
on 2009-01-30 00:23
(Received via mailing list)
Good to hear - this is definitely my preferred option.
Thanks much,
Scott
This topic is locked and can not be replied to.