• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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?
0
mortenmo
Asked:
mortenmo
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now