Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

unload classes?

Thread view: 
rmacnak@gmail.com - 29 Jul 2006 01:38 GMT
Is there (or could there be) a way to make the VM unload or reload a
class?
Martin Lansler - 29 Jul 2006 07:47 GMT
I know of two ways...

Using a custom classloader:
Tomact for instance will reload classes in a webapp context if the context
has been marked as reloadable. It should be possible to
write a custom classloader that does the same, some thought about this:
http://mindprod.com/jgloss/reloading.html

Using JPDA:
Eclipse for instance can reload classes during debugging using JVM
instrumentation.

Cheers,
Martin.

> Is there (or could there be) a way to make the VM unload or reload a
> class?
Thomas Hawtin - 29 Jul 2006 09:45 GMT
> Using a custom classloader:

Or a bog standard, uncustomised URLClassLoader.

http://download.java.net/jdk6/docs/api/java/net/URLClassLoader.html#newInstance(
java.net.URL
[])

> Tomact for instance will reload classes in a webapp context if the context
> has been marked as reloadable. It should be possible to
> write a custom classloader that does the same, some thought about this:

It's very easy to write code that will leak. For instance java.beans,
common uses of ThreadLocal and loading JDBC driver can all cause the
class loader and all of its classes and their static data to leak.

Tom Hawtin
Ian Shef - 07 Aug 2006 21:19 GMT
> Is there (or could there be) a way to make the VM unload or reload a
> class?

Yes.  It requires that there be no references to the class. However, the
class loader maintains a reference to each class that it loads.  Thus, you
must deal with the class loader, by creating (if I recall correctly) a custom
class loader.  This is not as hard as it may sound.

A solution is shown in:

Java Reflection in Action (In Action series) by Ira R. Forman and Nate
Forman  (ISBN: 1932394184 )

The book also explains the limits of this approach.

Disclaimer:  I have no connection with the publisher or the authors.  Just a
satisfied reader.

Signature

Ian Shef     805/F6      *    These are my personal opinions    
Raytheon Company         *    and not those of my employer.
PO Box 11337             *
Tucson, AZ 85734-1337    *



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.