Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Shutdown Hooks  RSS feed

 
Brian Knight
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Firstly my apologies if this is the incorrect forum for this post. I have an application that mantains a reference to a remote object. The remote object implements the Unreferenced interface and performs clean up when the client no longer references it. As a result when the client exits the application I set the reference to my remote object to null, and call System.gc(), which causes the Unreferenced method to be called on the remote object. This works fine if I set the reference to null from within windowClosing(), but if I put the same code in a shutdownhook, then it does not work. Is this because System.gc() will not run from within the shutdown hook? Is there any way to force this behaviour?

Thanks
Brian
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to guarantee garbage collection anyway; System.gc() is merely a request for the garbage collector to run, and I'm not surprised that the JVM doesn't think it's particularly useful to run garbage collection during shutdown. Is this a problem? The DGC lease will expire anyway and cause your Unreferenced callback to be called; if the default (10 minutes seems to ring a bell) is too long then you can always decrease the lease time at the expense of slightly more network traffic to renew leases.

- Peter
[ August 21, 2004: Message edited by: Peter den Haan ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!