Reloading java classes

If you have a running java application that have instances of the foo.bar class.

If you then recompile the bar.java file, the application seem not to pick up the new class file but rather stick with the old one.

Is it possible to make it so that new instances of the foo.bar class uses the newly compiled class instead of the old one?
LVL 1
mortenmoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sen_kumCommented:

   When the instance or a static member of the class is called in the application, the class will be loaded in the memory. So here after it will refer to the class in the memory and it will not reload from class file.

   For instance if the class is not refered in application until you recompile the class file then the new file will be loaded when it's refered
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mortenmoAuthor Commented:
So there is absolutly no way to make the class unloaded from the VM? Even if you destroy all instances of the class?
0
sen_kumCommented:
The VM will not unload the class at any time.

To achieve your goal you can write your own classloader class
The following site gives information of writing a custom classloader.

http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html

In the loadClass method first you check for the class in cache if it's cache you once again to try to load .
0
mortenmoAuthor Commented:
Just what I needed. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.