Forum: JRuby glassfish gem - shared singleton

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Scott M. (Guest)
on 2009-01-29 19:10
(Received via mailing list)
Hi Everyone,
I'm currently using the glassfish gem (0.9.1) with jruby (1.1.6) to host
rails application.  I'm wondering if there is a recommended/supported
way of
having a singleton shared among multiple jruby runtimes.  It appears
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?

Jacob K. (Guest)
on 2009-01-29 21:14
(Received via mailing list)
Not really... However, there are a few hack-ish things that you could

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:
Scott M. (Guest)
on 2009-01-29 22:00
(Received via mailing list)
Thanks for the response.  That was going to be my follow up question:
confident are people with the new thread-safe mode?  If it's solid (in
2.2.2), then I'd prefer to take that approach anyway (and save some
as well).
Ikai L. (Guest)
on 2009-01-29 23:37
(Received via mailing list)
It's solid. We're running it on our production JRuby applications at

If you use MemCache, either enable threadsafe mode in memcache-client or
JRuby-MemCached wrapper

Ikai L. (Guest)
on 2009-01-29 23:39
(Received via mailing list)
I should also mention additional benefits of running a single JRuby

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

Scott M. (Guest)
on 2009-01-30 01:23
(Received via mailing list)
Good to hear - this is definitely my preferred option.
Thanks much,
This topic is locked and can not be replied to.