Flushing the cache Dynamically

I'm not sure if this is the right place for this or exactly how to phrase the question, so here goes.

Is it possible/there a way to flush the class dynamically?

What I want to do is load a class. Modify it using BCEL, compile it and then reset it back to the original class loaded. If that makes any sense. Is this doable or will I have to load the class each time?

Thanks.

[399 byte] By [legsa] at [2007-10-2 5:44:18]
# 1
Classes are unloaded if the classloader that loaded the class is GCed, IIRC...
CeciNEstPasUnProgrammeura at 2007-7-16 1:54:17 > top of Java-index,Java Essentials,Java Programming...
# 2
But I don't want to have to unload the class. Thats a last resort.I'd like to load a class. Modify it. Flush the cache. Modify it again. Flush the cache. etc etc
legsa at 2007-7-16 1:54:17 > top of Java-index,Java Essentials,Java Programming...
# 3

> reset it back to the original class loaded.

> Is this doable or will I have to load the class each time?

You want to replace the code of a class? This is called loading the class, so you don't "have to", you "get to" do it :-)

As Rene said, discard the class loader.

There may a way to redefine a class using java.lang.instrument.Instrumentation. Check out redefineClasses() there. Google for all of that. This is however not supported by all JDKs, meant for debugging, and has a number of constraints (see redefineClasses() javadoc). You probably shouldn't try to use it for anything production-like, only for debugging. It'll lead to tears, I tell you... The right way to redefine classes in a production environment is to discard the class loader.

sjasjaa at 2007-7-16 1:54:17 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks
legsa at 2007-7-16 1:54:17 > top of Java-index,Java Essentials,Java Programming...
# 5
Sun discarded a project to do this (while debugging) as not feasible.
ChuckBinga at 2007-7-16 1:54:17 > top of Java-index,Java Essentials,Java Programming...