Hi Ram,
The main problem I'm seeing with your situation is that you are hot deploying only a section of your application. Programs like JBoss use hot deployment but deploy a self contained group of classes and each deployment gets its own class loader instance. You could download it for free at
http://www.jboss.org/ and check out their source code for ideas.
In your case you have a class which can possibly change over time interacting with other classes which do not change. There is a huge problem if the class or classes you are hot deploying are going to change their API. If methods are being added / removed then this is very difficult and it would probably be easier to just restart the server while developing.
A possible way would be to have an interface or abstract base class that the "hot classes" would implement / extend. You would put the interface in the stable jar and the new implementations would be in the hotdeploy.jar. A factory method or class would create instances of the interface by getting the latest implementation.
As for getting rid of old versions of the class you might want to consider an event based notification model. (Keep in mind that this is just my initial idea on how I might approach it. I haven't coded this and tested if it would work.) I was thinking that there would be something like a ClassUpdateListener interface that would have to be implemented by anything that keeps a reference to one of these hot classes. The factory that creates instances would offer a method like:
The factory would in this case perhaps have an internal thread doing the watching. When a new version is loaded it would make a callback to classes that have gotten instances from it.
In this way everyone who has a reference to one of the old classes could copy information into a new instance of the class using the well known methods defined in the base class or interface for the hot class. Once the instances of the old class have no references to them, they are eligable for garbage collection.
I have to say though that I would not go through all of this trouble if this hot deployment is not a feature of the end product. If this is solely for the purpose of ease of development then I'm not sure that all this is worth it. (Other than for the experience of having done it, of course
)