unload classes?

M

Martin Lansler

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.
 
T

Thomas Hawtin

Martin said:
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
 
I

Ian Shef

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top