JVM not shutting down when referring to AWT type

I have noticed that when I refer to AWT/Swing types from JRuby, the
JVM doesn’t seem to shut down after code execution completes. Here is
a very simple code sample that demonstrates the problem:

require ‘java’

Component = java.awt.Component

When I add this to a file called foo.rb and run: jruby foo.rb, I see a
process start up called ‘org.jruby.Main’ that will only die if I
transfer focus to another running application. I am running OSX
(10.5.4), JDK 1.6.0_05, and JRuby 1.1.3.

Can anyone tell me what is causing this or how prevent the JVM hanging
around?

–Mario

Hi Mario,

Interesting, and unexpected. It works for me on Windows and Linux.
Typically, this kind of thing happens when there is some non-daemon
thread left behind and hence Java can’t exit due to this.

Can you run your sample and then produce the stack trace (on Linux
it’s Control-\ and on Windows it’s Control-Break , I’m not sure which
one would work on MacOS, but my bet is on Control-\ ).

In the stack trace, you could see the list of current threads, that
might give a clue.

Also, possibly putting ‘exit’ at the end should eliminate the problem.

Thanks,
–Vladimir

On Tue, Jul 29, 2008 at 4:47 PM, Mario A. [email protected]
wrote:

process start up called ‘org.jruby.Main’ that will only die if I transfer
focus to another running application. I am running OSX (10.5.4), JDK
1.6.0_05, and JRuby 1.1.3.

Can anyone tell me what is causing this or how prevent the JVM hanging
around?

–Mario


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Mario A. wrote:

process start up called ‘org.jruby.Main’ that will only die if I
transfer focus to another running application. I am running OSX
(10.5.4), JDK 1.6.0_05, and JRuby 1.1.3.

The application you see is just your running JRuby instance. It only
shows up as a normal app in the dock and task list after loading
Component because until then Java tries to run “headless” by default.

Can anyone tell me what is causing this or how prevent the JVM hanging
around?

Part of pulling in any AWT or Swing components is that they start a
non-daemon event thread. Normally this thread does not shut down until
all visible components are no longer visible, but it doesn’t seem to
work that way on OS X for some reason.

In general, there are two ways to get an app with a Swing/AWT event
thread to shut down:

  • close all visible components, which in this case obviously isn’t the
    answer
  • call java.lang.System.exit(0) which will immediately terminate the
    JVM.

We’ve had various discussions about whether the Ruby Kernel#exit should
cause the event thread to shut down, and in general the fear of adding a
hard System.exit call to JRuby was too great to go that direction. So I
feel like the event thread is more just “something you have to know
about” when pulling in Java GUI components.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Vladimir & Charlie,

Thanks for responding! The call to System.exit() is unfortunate, but
it does work for my needs. This problem is the most annoying when I
try to run a test suite for a framework that uses Swing (Monkeybars).
I can wrap the rake task that launches the tests to call System.exit()
afterwards, but I wish I didn’t have to. I wonder what it is about
the Apple JVM that causes this difference in behavior (compared to the
Sun JVMs).

–Mario

There is a Java property you might try to set that enables (forces?)
headless execution:

-Djava.awt.headless=true (and that would be -J-D from JRuby command
line)

That might help…let us know if so, and perhaps add a FAQ somewhere on
the wiki for it at wiki.jruby.org

Mario A. wrote:

–Mario

When I add this to a file called foo.rb and run: jruby foo.rb, I see


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Mario,

On Tue, Jul 29, 2008 at 4:47 PM, Mario A. [email protected]
wrote:

When I add this to a file called foo.rb and run: jruby foo.rb, I see a
process start up called ‘org.jruby.Main’ that will only die if I transfer
focus to another running application. I am running OSX (10.5.4), JDK
1.6.0_05, and JRuby 1.1.3.

Can anyone tell me what is causing this or how prevent the JVM hanging
around?

I talked to our local AWT experts, and it seems that this is indeed
just a bug in Apple’s JDK version. I see that similar bugs were fixed
in some recent OSX versions, but maybe there are more.

Could you show the stack trace from your example, just in case?

Thanks,
–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email