• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX:How to handle the Distributed Garbage Collection?

 
Jamy Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had implements java.rmi.server.Unreferenced, but I still can't see it works... Why?


Could you tell me how to realize distributed garbage collection?
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please explain a little more of what your trying
to accomplish in regards to the project/exam.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,
I can't see anything wrong with the bits of code you posted. Some possibilities:
  • Did you release the reference to your instance of Test on the client side?
  • Did you wait more than the minimum time before the DGC would be called (default 20 minutes) for unreferenced to be called?


  • When you release the reference to the remote object on the client side you can try calling the garbage collector on the client side - this usually triggers the distributed garbage collector.
    Here's some sample code to show Unreferenced being called. I have both client and server parts in one file.

    Try that. You should see that unreferenced gets called as soon as the garbage collector is called on the client side.
    Things to try from there:
  • Comment out the line "System.gc();" (which is in the client code) and try running it again. How long does it take before Unreferenced gets called?
  • Change the value set for "java.rmi.dgc.leaseValue" and try running it again. How long does it take before Unreferenced gets called? What do you think is guaranteed by this value?
  • Comment out the line which sets "java.rmi.dgc.leaseValue" and try running it again. Now how long does it take?
  • Try running the client code in the same thread as main() (Change the line "new Client().start()" to "new Client().run()"). Now how long does it take for Unreferenced to be called? Why?


  • Have fun
    Regards, Andrew
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12007
    215
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Bill,
    Bill Robertson:
    Could you please explain a little more of what your trying to accomplish in regards to the project/exam.

    Those people who are developing fat clients (so the client code calls the lock() method) have the potential problem that if the client crashes or the network connection is dropped, then they could have a locked record which cannot be unlocked.
    Three common strategies for handling this are:
  • Document the potential problem, but otherwise ignore it (not very professional IMHO, but people have passed doing this)
  • Implement Unreferenced using a Factory in the RMI server so that you (eventually) get notified that the client is no longer connected and can clean up outstanding locks.
  • Use a WeakHashMap or some other WeakReference to automagically clear up locks which no longer have a strong reference.


  • Regards, Andrew
     
    Bill Robertson
    Ranch Hand
    Posts: 234
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ooohhhhh I see. thanks andrew
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic