• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

RMI Reaper Thread

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a Java application that uses Spring for its RMI needs. I tried to lookup a bean, and it didn't exist, so the application crashed as expected. However, the application hung indefinitely because of the non-daemon thread "RMI Reaper" that was running. Does anyone know what this thread is and why it would hang like this?

Thanks,
Jeff
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say the application crashed, what is it you mean?
You got a Null pointer?
If so, then this means that the request thread died and not the JVM crashed.
RMI creates keep alive threads to keep the VM alive till the point there are no remote objects existing in the JVM.
RMI keeps a count of the number of remote objects exported via RMI.
RMI reaper polls the reference queue for the objects that were exported and hence when these objects are garbage collected, the RMI reaper removes them from its object table and mark it for removal.
RMI reaper keeps the VM alive till the time there are any non-permanent RMI objects alive in the JVM.
Also, this does not mean that the RMI reaper thread is hung, it is just doing its job i.e. waiting for the exported objects to be GCed.
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that info. By crashed, I mean that I got a Spring exception saying that the bean does not exist. I guess maybe in the "finally" block that launches my application I need to clean up all the beans or something like that (they all cleanup under normal run circumstances).
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.exit() is the only way to end an RMI Server. There are other threads active in the RMI Runtime as well.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Edward Harned:
System.exit() is the only way to end an RMI Server.



Really? Yuk.

CORBA doesn't have that problem - well, not the home-made ORB that we have, anyway. Strange that RMI should be less friendly.
 
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "RMI Reaper" thread is spawned when you create a registry using RMI (e.g. LocateRegistry.createRegistry(port)).

Edward Harned wrote:System.exit() is the only way to end an RMI Server. There are other threads active in the RMI Runtime as well.


This is completely incorrect. The correct way to shutdown the "RMI Reaper" thread is to unexport all objects that have been exported. Once this is done, your program will terminate normally.
See this post on StackOverflow for examples on how to do that.

This is because the "RMI Reaper" thread is a non-daemon thread, and according to the Javadocs,  "The Java Virtual Machine exits when the only threads running are all daemon threads."

If you'd like to print the list of all threads that are running that are non-daemon threads, use this code - these are threads that must be cleaned up before the JVM will exit on its own.


It would be best you put this at the end of the execution of your program, so you can see what threads are still alive that need cleaning up for the program to exit normally.
 
Marshal
Posts: 81617
593
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Good point, but EH hasn't posted since 2013 and please don't hold your breath waiting for a reply
 
Kenny Hanamura
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. That's alright, I think it's good to leave for other people who stumble upon the thread with the same question
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic