Results 1 to 5 of 5
  1. #1
    luoluo is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default How to unload previous class when it has loaded

    Hi everyone,

    I have a issue about JVM.

    I have loaded my class file,when I don't use this class,I want to unload this class  from JVM,as don't let this class to inside JVM al l the time,or sometimes I fix my class,so I have t o reload to replace my originality class.

    can anyone help me.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    I don't believe it is possible to have a class unloaded. it is possible to have a class re loaded, such as a new version of the class, as tomcat and other servlet containers do for you when you redeploy the .war file or recompile the .class files. Also, considering how JSP pages are transcoded into .java files and automatically compiled into .class files. These also get replaced, but never really completely remove the previous class image, in the permanent generation, or permgen space. It is possible to use JVM arguments to tune the percentage of heap size allocated to permanent generation (e.g. loaded classes), but eventually, after (re)loading enough classses the permgen space runs out and the vm needs to be rebooted.

    so (I think) the only way to have a class unloaded is to have the underlying java vm restarted ??

  3. #3
    luoluo is offline Member
    Join Date
    Apr 2010
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by travishein View Post
    I don't believe it is possible to have a class unloaded. it is possible to have a class re loaded, such as a new version of the class, as tomcat and other servlet containers do for you when you redeploy the .war file or recompile the .class files. Also, considering how JSP pages are transcoded into .java files and automatically compiled into .class files. These also get replaced, but never really completely remove the previous class image, in the permanent generation, or permgen space. It is possible to use JVM arguments to tune the percentage of heap size allocated to permanent generation (e.g. loaded classes), but eventually, after (re)loading enough classses the permgen space runs out and the vm needs to be rebooted.

    so (I think) the only way to have a class unloaded is to have the underlying java vm restarted ??

    If you have new version class file,how to reload to replace older version.

  4. #4
    xerberuz is offline Member
    Join Date
    Apr 2010
    Posts
    8
    Rep Power
    0

    Default

    IMHO a class is unloaded if no object of this class exists and the classloader of the class is unloaded itself. I guess OSGi works exactly this way. But I'm not sure so the best idea to see how it works is to check out the OSGi base project and have a look on the classloading mechanism.

    Anyway, I would recommend to use OSGi for such requirements.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,734
    Blog Entries
    7
    Rep Power
    21

    Default

    Have a look at Java Rebel; it's not free but you can get an evaluation version (I downloaded it once) and it's fun. Basically it's a class loader that checks for new file images of the classes it already loaded; if it finds a newer image and there is nothing using the code and data in that particular class (this is the most important part) it reloads the class.

    kind regards,

    Jos

Similar Threads

  1. calling the servelet code when the page is loaded
    By shivakumari in forum Java Servlet
    Replies: 1
    Last Post: 04-01-2009, 12:39 PM
  2. Storing image loaded in applet in mysql database
    By mrvigneshmca in forum Java Applets
    Replies: 1
    Last Post: 03-20-2009, 05:17 PM
  3. Replies: 0
    Last Post: 02-15-2008, 09:41 AM
  4. Replies: 1
    Last Post: 08-08-2007, 03:42 PM
  5. newbie: the app is loaded but i can't see it
    By tamayo in forum New To Java
    Replies: 1
    Last Post: 07-21-2007, 09:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •