Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can System.gc() call unreferenced()?

 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I have experimented on the Unreferenced interface. I realized that when my dummy test client disconnects, sometimes unreferenced() is called, but sometimes it doesn't. Even during the times when it doesn't, it gets called after 15 minutes due to the lease. However, the strange thing is that on the dummy test server, I ran a thread that calls System.gc() every 10 seconds. No matter what, the garbage collector never seem to call the unreferenced() method. Why? In the first place, is System.gc() the correct method to call?

Another thing, in my unreferenced() method, do I have to add in any cleanup codes like UnicastRemoteObject.unexport(this, true) or anything similar?
[ February 06, 2005: Message edited by: Liang Anmian ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do realised that System.gc() is not guaranteed to actually do anything?
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. How could I have forgotten about that? To think that my programmer exam was only last week.

So I guess there's no way to detect lost clients on the spot. It's ok. Not that big of a problem though.

Thanks for the reply anyway.
[ February 06, 2005: Message edited by: Liang Anmian ]
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Liang Anmian:
Oops. How could I have forgotten about that? To think that my programmer exam was only last week.

So I guess there's no way to detect lost clients on the spot. It's ok. Not that big of a problem though.

Thanks for the reply anyway.

[ February 06, 2005: Message edited by: Liang Anmian ]


When your client disconnects properly the Distributed Garbage Collection (rmi.dgc) tends to call unreferenced() almost immediately, but you should use some sort of disconnect method to guarantee that this happens. I tested it on W2K and dgc calls unreferenced almost immediately after I call disconnect and set the client DataProxy object to null. I haven't tested that on Solaris, but I suspect its the same since I'm running the Sun JRE on both.

I added connect and disconnect methods to the Data and DataProxy classes using a Session interface. This makes it easy to control session activity.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic