Raising Notifications from RMI

Ever wish you could have your RMI application notify you when it’s using the distributed garbage collector? Sometimes it’s useful to know when a RMI server “kills” an object. Just perform the following steps:

  1. Implement the java.rmi.server.Unreferenced interface in your RMI server.
  2. Provide an implementation for the unreferenced() method.
  3. Specify a value for the java.rmi.dgc.leaveValue system property. This value represents miliseconds (default ten minutes) and it is used to tell how much time must pass without clients interaction before an object is collected.
  4. The client’s interaction represents a “lease contract” that must be updated.

What follows is an example of an RMI server that returns the timestamp of a collected object:

import java.rmi.*;import java.rmi.server.*;import java.util.Properties;public class SumImpl extends UnicastRemoteObject implements SumInterface,Unreferenced{   public SumaImpl()throws RemoteException   {      //optional      super();   }   //the SumInterface method   public int Sum(int a,int b)throws RemoteException{      return (a+b);     }   //the unreferenced method   public void unreferenced()   {      java.util.Date date=new java.util.Date();      System.out.println("Unreferenced called..."+date);   }   //the finalize method   public void finalize()throws Throwable   {      super.finalize();      java.util.Date date=new java.util.Date();      System.out.println("Finalize called..."+date);   }   public static void main(String[] args)   {                    SumImpl SI=null;      //create the remote object      try{         SI=new SumImpl();             }catch(java.rmi.RemoteException e)         {System.out.println(e.getMessage());}      	      try{                 Naming.bind("rmi://localhost:1099/SUMObject",SI);      }catch(java.rmi.AlreadyBoundException e)         {System.out.println(e.getMessage());      }catch(java.net.MalformedURLException e)         {System.out.println(e.getMessage());      }catch(java.rmi.RemoteException e)         {System.out.println(e.getMessage());}               }}

The SumInterface is a simple interface that contains a single method, called Sum. Write this interface and a clasic RMI client, and run the RMI server like this:

<HOME>java ?Djava.rmi.dgc.leaveValue=1000 SumImpl
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a