Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

Fundamentals of RMI

Distributed Garbage Collection

by jGuru

[Help | API Docs | Short Course| Exercises]

In this exercise you will observe the behavior of the distributed garbage collector and the local garbage collector working together to manage memory.

There is no code to write, but you have to change the value of the constant HOST_NAME to match your computer name. You will also want to look at the code of the classes that make up this example, especially MessageObjectImpl to understand exactly how it works.

In this exercise there are two remote objects, Hello and MessageObject. Their implementations are designed to print out information when they are created, unreferenced, finalized and then deleted.

A remote object can implement the Unreferenced interface and its one method, unreferenced. This method is called by the DGC when it removes the last remote reference to the object. MessageObjectImpl and HelloImpl are designed to print a message when this happens.

MessageObjectImpl and HelloImpl also implement the finalize method. This is called when the local garbage collector is about to destroy an object and reclaim its memory space. In this implementation, MessageObjectImpl and HelloImpl prints a message to the console.

The course material for this exercise is covered in Distributed Garbage Collector.

To run this exercise, you run RMIServer and two copies of the client, RMIClient.

As you run this exercise, you may want to experiment with the setting of the Java heap size (use the -mx command line argument) and you may wish to explicitly set the DGC remote reference leaseValue. To change this, use the following command line:

java -Djava.rmi.dgc.leaseValue=10000 RMIServer

where the unit of time for leaseValue is in Milliseconds.

Back to Top

Skeleton Code

Tasks


  1. Change the value of the constant HOST_NAME in RMIClient.java and RMIServer.java to match the name of your computer.

  2. Compile all Java source files.

  3. From the Solution subdirectory, run the server, RMIServer with the smallest heap possible.

  4. Run two instances of the client.

Where help exists, the task numbers above are linked to the step-by-step help page.

Back to Top

Solution Source

Demonstration

When the server is run in its DOS console, the output will be:

Registry created on host computer ROSA on port 10007 Remote HelloService implementation object created Bindings Finished, waiting for client requests.

Then when the client is run in its DOS console, the output will be:

HelloService lookup successful Message from Server: Hello!

As the two clients run, each DOS console will display messages.

The server console will display messages as follows:

MessageObject: Class Number is #1882 Object Number is #1882
MessageObject: Unreferenced for object #: 1841
MessageObject: Finalize for object #: 893

Each of the client consoles will display an output similar to this:

MessageObject: Class Number is #1882 Object Number is #1882

Observe how the Server console indicates when the GDC and local garbage collector are working.

Next Magercise

Exercises

Short Course

Feedback

Back to Top

Copyright 1996-2000 jGuru.com. All Rights Reserved.


[ This page was updated: 25-Feb-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.