Re: Possible to unload classes?

You make a classloader that is loading classes from somewhere other than the classpath.

ArkAvon wrote:
Alright, what I am trying to do is to allow the user to input a java class file into a text editor within the program.You mean a java source file.
Then the program will take the code, compile it into a classfile, and then load it via a classloader and start it executing. Now, if the user alters the code in his box and saves it again as the same filename, the same classname is used in compilation and then the classloader tries to load the new class, but it has the same name as the old one, so it just uses the old one. I need to get rid of the old one.
So as noted you are not loading it via the custom class loader. That is a matter of the output dir being in the VM class path. It should be.
Is the classpath just the path of the classes of the program being run? The class path is the class path. In the Sun VM it consists of a user configurable path along with the VM paths.
Even with this set up, it still bucks it back up to bootstrap loader.Because you have it in the VM class path.

Similar Messages

  • Is it possible to unload a class?

    Suppose I take a classloader and load a class. Then I set my classloader to null and get rid of any objects of it that I've instantiated. Can that class be garbage collected?
    I'm thinking that it probably isn't possible. Even if you can get rid of all references to the class, what if a thread is running a static method of that class? But then again I suppose the stack trace would then have a reference so it can't be garbage collected. Was also thinking about what if a thread is just about to call it, but I guess you could just pop a classNotFoundException. So maybe it is possible... Can anyone comment?

    Well... I'm pretty sure it's possible to unload a class since it's possible to replace them. My IDE (IntelliJ) is capable of recognizing a change in your class file (as a result of compilation while the program is running, for example) and inserting the new class into the application if you want. This is very handy for working on web applications wherein the server takes a while to reload the application.
    So if you can reload the class, you can probably unload it, yes?

  • Is it possible to unload a class thru the standard Classloader

    is it possible to unload a class thru the standard Classloader,
    I mean during runtime..

    If you want do unload any class then create separate custom class loader and load it with it.
    When you don't need anymore that package you can simply set your custom class loader to null and the next time GC is invoked it may free the memory.
    If you want to free it right after you don't need that package anymore you should call System.gc() twice -
    this usually works.

  • Unload class (to free static references)?

    My problem: apache fop has a bug that it has a static Map field in a class that increases constantly. Is it possible to "unload" this class to ensure freeing up the references from this static field? And subsequent calls would reload the class when needed?

    Those streams often are created within a method
    and there's no reference (variable) to it outside
    the method (e.g. in the class or super class)?Not sure that reflection will provide you with a work-around for this; although, you could write your own classloader to load JFreeChart, and have it provide your own implementation of ImageInputStream which retains references to un-closed streams so they can be killed off later.
    We're definitely on the way to the land of ick with this sort of hack, though... I think maintaining your own fork of the source code and keeping it in sync with the main project might actually turn out to be easier. That or beating the dev's around the head to get your fixes accepted.
    Dave.

  • How to Unload Classes?

    i have created custom classloader. now i want to unload classes those are loaded by custom classloader.
    i know that the classes will be unloaded when its classloader is unloaded. so i want to know how to unload cusotm classloader.
    In ClassLoader class there is one static inner class it has unload method . but we can not access that method from custom classloader.

    as a rule of thumb,
    an object of may get marked for gc once no reachable references to it exist in the system.
    a type (class) gets unloaded once:
    1) no reachable references to it exist in the system;
    2) there are no instance of that type left in the system or all the instances are unreachable (which is essencially the same as 1)
    a classloader gets unloaded once there are no reachable references to it exist in the system.
    reachable is the keyword here. Otherwise, if you had two classes A & B references each other, they would never be marked for gc. But as long as no other reference to either A or B exist, they both can be gc'ed. The same applies to classloaders (after all, they are just regular objects). Even though type T holds a reference to its classloader, if nothing refers to T, it's reference to the classloader doesn't count.

  • Is it possible to refer class files by mapping network drive?

    Hi,
    Is it possible to refer class files from the server(By mapping network of client's server) and specify this in project setting. If yes, how?
    Right now I copied all class file needed, to 'myclasses' directory of jdevhome. this approach is working fine but the page is taking 20 to 30 minutes to refresh.
    What could be probable reason for taking this much time to refresh a page? what could be alternative for this?
    Will the mapping of drive and referring it will improve the performance?
    I am connected to server through VPN and using Window based JDeveloper.
    Regards,
    Adarsh

    Hi Adarsh,
    For the first part of your query, You can create a new Library in Project Settings to refer to the server classes.
    As for the performance issue, there could be many reasons. Do you really think class loading is the only reason for the same? You might want to check in the Log window as to which process is eating up your time before loading the page.
    ~Srinath.

  • Is it possible clear the class loader cache programatically?

    Hi,
    Is it possible clear the class loader cache programatically?
    Thanks

    By the cache do you mean the loaded classes? If so, you can do that by discarding any pointer you have to the class loader and creating a new class loader. ...though I wonder why you would need to do that...

  • Web application Unloading classes of WL Stubs every several hours

    Hello,
    We have a WEB applications, which connects to Server Application using EJB technology - both deployed on the same
    domain on Weblogic 10.
    Recently, we started to experience a strange phenomenon - WEB application's threads get stalled and get a STUCK
    state.
    Sometimes, it is accompanied with the java.lang.OutOfMemoryError exception.
    Only reboot helps to recover from it.
    Trying to identify a problem we added some parameters to get some more information in the application logs.
    What we found is that once in a while (depend on a system load), we see the following messages in console logs:
    [Unloading class <class name>]
    These are the examples about how often the events happen and it’s durations:
    2011-01-30 10:14:11 - 2011-01-30 10:14:28
    2011-01-30 12:27:51 - 2011-01-30 12:28:08
    2011-01-30 13:59:46 - 2011-01-30 14:00:02
    2011-01-30 14:56:59 - 2011-01-30 14:57:13
    2011-01-30 14:57:46 - 2011-01-30 14:58:00
    2011-01-30 17:11:21 - 2011-01-30 17:11:39
    2011-01-30 18:29:24 - 2011-01-30 18:29:44
    2011-01-30 20:05:34 - 2011-01-30 20:05:53
    2011-01-30 21:48:39 - 2011-01-30 21:48:55
    . - Each time are about 20000 - 30000 classes are unloaded.
    . - About 150000 classes are unloaded daily,
    ........- 90% out of it are the classes, which ends with "*..Impl_1001_WLStub*"
    ............- 30% out of Stubs are Home Stubs, which ends with "*..HomeImpl_1001_WLStub*"
    *(!) The most interesting that out of all this huge amount of classes, which are unloaded daily,*
    only +23+ types of different Stubs are unloaded, whereas out of it +10+ different Home Stubs:
    $> grep "Unloading class.*Impl_1001_WLStub" Web1.out | sort -u | wc -l
    23
    $> grep "Unloading class.*HomeImpl_1001_WLStub" Web1.out | sort -u | wc -l
    10Sometimes (as I said above) it ends with the "+java.lang.OutOfMemoryError+" exception.
    So, the questions are:
    1. What could be a reason for such behavior of a system?
    2. What message "Unloading class" says?
    3. Is it normal that (as you see from above), the same type of Stubs are loaded?
    It looks like a new Stub is created for every EJB invocation, isn't it?
    Is it normal? If not, what could be a reason for this?
    --------------- S Y S T E M ---------------
    jvm_args: -Xms2048m -Xmx2048m -XX:MaxPermSize=512m
    OS: Solaris 10 5/08 s10s_u5wos_10 SPARC
    uname:SunOS 5.10 Generic_142900-02 sun4v (T2 libthread)
    rlimit: STACK 8192k, CORE 1024000k, NOFILE 65536, AS infinity
    CPU:total 64 has_v8, has_v9, has_vis1, has_vis2, is_ultra3, is_sun4v, is_niagara1
    Memory: 8k page, physical 66977792k
    vm_info: Java HotSpot(TM) Server VM (1.5.0_11-b03) for solaris-sparc, built on Dec 15 2006 01:18:11

    You could see how your memory is managed by the JVM, by using for example a tool such as jconsole.
    Unloading class means that loaded classes are garbage collected. To see when the classes are loaded
    you can use the JVM option -verbose:class. I think somehow you are constantly loading the classes in the application,
    maybe by creating the stub over and over again when you need it. You can create the stub once by using
    a singleton pattern.
    A good overview of the available tools for the Sun JVM is given here: http://www.oracle.com/technetwork/java/javase/index-137495.html

  • Unloading class sun.reflect.GeneratedConstructorAccessor

    Hello All,
    I have thousands of lines in my log combined with "concurrent mode failure"
    [Unloading class sun.reflect.GeneratedConstructorAccessor1941]
    [Unloading class sun.reflect.GeneratedConstructorAccessor2003]
    [Unloading class sun.reflect.GeneratedMethodAccessor1184]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1994]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1977]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1999]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1976]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1981]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1921]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor1758]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1993]
    [Unloading class sun.reflect.GeneratedMethodAccessor1177]
    Does it mean that permanent generation have a small size and the class is constantly unloaded?
    Thanks

    Don't do this.
    http://java.sun.com/products/jdk/faq/faq-sun-packages.html

  • Garbage collector - Tenured Generation - Unloading Class

    Hi All,
    I've seen the garbage collector report the following.  The worrying this is it took 36 seconds.  Is this normal, or is there something wrong with my generation (New, Perm, Tenured) sizes ?  What does this "Unloading Class" mean?
    Thu Dec  7 10:06:20 2006
    57165.190: [GC 57165.190: [ParNew: 676789K->676789K(682688K), 0.0000346 secs]57165.190: [Tenured
    Thu Dec  7 10:06:34 2006
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor116]
    [Unloading class sun.reflect.GeneratedConstructorAccessor819]
    [Unloading class sun.reflect.GeneratedMethodAccessor1]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor256]
    [Unloading class sun.reflect.GeneratedConstructorAccessor405]
    [Unloading class sun.reflect.GeneratedMethodAccessor232]
    [Unloading class sun.reflect.GeneratedMethodAccessor328]
    [Unloading class sun.reflect.GeneratedConstructorAccessor989]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor212]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor37]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1032]
    [Unloading class sun.reflect.GeneratedConstructorAccessor366]
    [Unloading class sun.reflect.GeneratedConstructorAccessor89]
    [Unloading class sun.reflect.GeneratedConstructorAccessor84]
    [Unloading class sun.reflect.GeneratedConstructorAccessor336]
    [Unloading class sun.reflect.GeneratedConstructorAccessor335]
    [Unloading class sun.reflect.GeneratedConstructorAccessor1053]
    [Unloading class sun.reflect.GeneratedConstructorAccessor418]
    [Unloading class sun.reflect.GeneratedMethodAccessor320]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor86]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor274]
    [Unloading class sun.reflect.GeneratedConstructorAccessor929]
    [Unloading class sun.reflect.GeneratedConstructorAccessor893]
    [Unloading class sun.reflect.GeneratedConstructorAccessor444]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor58]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor144]
    [Unloading class sun.reflect.GeneratedConstructorAccessor132]
    [Unloading class sun.reflect.GeneratedConstructorAccessor385]
    [Unloading class sun.reflect.GeneratedConstructorAccessor767]
    [Unloading class sun.reflect.GeneratedConstructorAccessor960]
    Thu Dec  7 10:06:57 2006
    : 1653530K->1018272K(2326528K), 36.6689289 secs] 2330319K->1018272K(3009216K), 36.6692910 secs]
    Our server has 16GB of RAM.  The Heap size is currently set to 3GB.  The NewSize is 800MB and the Perm Size is 384MB.
    Thanks in advance
    Regards
    Anthony Gray

    Hi,
    > Hi All,
    >
    > I've seen the garbage collector report the following.
    > The worrying this is it took 36 seconds. 
    That's for sure too long.
    > Is this
    > normal, or is there something wrong with my
    > generation (New, Perm, Tenured) sizes ?  What does
    >  this "Unloading Class" mean?
    A class is unloaded, when it's not used anymore.
    In your case its the unloading of classes that were automatically generated because of the use of Java reflection.
    I mentioned that by the way just recently in my web log here : https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5138. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
    What JVM do you use and what is the operating system  ?
    Regards,
    Markus
    >
    > ****************************
    > Thu Dec  7 10:06:20 2006
    > 57165.190: [GC 57165.190: [ParNew:
    > 676789K->676789K(682688K), 0.0000346 secs]57165.190:
    > [Tenured
    > Thu Dec  7 10:06:34 2006
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor1
    > 16]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor819]
    > [Unloading class
    > sun.reflect.GeneratedMethodAccessor1]
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor2
    > 56]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor405]
    > [Unloading class
    > sun.reflect.GeneratedMethodAccessor232]
    > [Unloading class
    > sun.reflect.GeneratedMethodAccessor328]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor989]
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor2
    > 12]
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor3
    > 7]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor1032]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor366]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor89]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor84]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor336]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor335]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor1053]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor418]
    > [Unloading class
    > sun.reflect.GeneratedMethodAccessor320]
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor8
    > 6]
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor2
    > 74]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor929]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor893]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor444]
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor5
    > 8]
    > [Unloading class
    > sun.reflect.GeneratedSerializationConstructorAccessor1
    > 44]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor132]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor385]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor767]
    > [Unloading class
    > sun.reflect.GeneratedConstructorAccessor960]
    > .
    > .
    > .
    > .
    > Thu Dec  7 10:06:57 2006
    > : 1653530K->1018272K(2326528K), 36.6689289 secs]
    > 2330319K->1018272K(3009216K), 36.6692910 secs]
    >
    > ************************************
    > Our server has 16GB of RAM.  The Heap size is
    > currently set to 3GB.  The NewSize is 800MB and the
    > Perm Size is 384MB.
    >
    >
    > Thanks in advance
    >
    > Regards
    > Anthony Gray

  • Is it possible to load classes from a jar file

    Using ClassLoader is it possible to load the classes from a jar file?

    URL[] u = new URL[1] ;
    u[0] = new URL( "file://" + jarLocation + jarFileName + "/" );
    URLClassLoader jLoader = new URLClassLoader( u );
    Object clsName = jLoader.loadClass( clsList.elementAt(i).toString() ).newInstance();
    I get this error message.
    java.lang.ClassNotFoundException: ExceptionTestCase
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
    // "file://" + fileLocation + fileName + "/" This works fine from a browser.
    Is there anything I am missing? Thanks for the reply.

  • Is Overloading possible in Sub class

    In every book I found that Overloading means method with the same name and with different parameter define in same class.
    But is possible if I define method with the same name and with different parameter in Sub class?
    Like example given below :
    public class OverLadingTest {
         public void test(int a, int b) {
              System.out.println("Inside test(int a, int b)");
         public static void main(String args[]){
                   OverloadedSubclass overloadedSubclass = new OverloadedSubclass();
                   overloadedSubclass.test(10.20,10.20);
    class OverloadedSubclass extends OverLadingTest {
         public void test(double a, double b) {
              System.out.println("Inside test(double a, double b)");
    Thanks in advance.

    The nays have it!
    package forums;
    class Singularity
      public void test(int a) {
        System.out.println("Singularity.test(int a)");
    class Universe extends Singularity
      @Override
      public void test(int a) {
        System.out.println("Universe.test(int a)");
      public void test(int a, int b) {
        System.out.println("Universe.test(int a, int b)");
    public class OverloadingTest
      public static void main(String args[]) {
        Singularity s = new Universe();
        s.test(10);
        s.test(10, 20);
    compile
    C:\Java\home\src\forums>"C:\Program Files\Java\jdk1.6.0_12\bin\javac.exe" -Xlint -d C:\Java\home\classes -cp c:\java\home\src; C:\Java\home\src\forums\OverloadingTest.java
    C:\Java\home\src\forums\OverloadingTest.java:27: test(int) in forums.Singularity cannot be applied to (int,int)
        s.test(10, 20);
         ^
    1 errorI'd say that's pretty conclusive, wouldn't you? Go read up on Java's definition of a [method signature|http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html]... It's not just the name, putz!
    Cheers. Keith.

  • Possible with tween class...

    Can you using the tween class have your tween go into a certain point? i.e. certain coordinates?

    What do you mean by using two tweens simulataneously...currently here is the script Im using..
    import mx.transitions.Tween;
    SceneZoomer = ;
    for (var j:Number = 0; j < SceneZoomer.length; j++) {
        SceneZoomer[j].onPress = function() {
            zoomIn(map);
        SceneZoomer[j].onRollOut = function() {
            zoomOut(map);
    function zoomIn(mc:MovieClip) {
        var xs:Tween = new Tween(map, "_xscale", mx.transitions.easing.None.easeOut, map._xscale, 275, 2, true);
        var ys:Tween = new Tween(map, "_yscale", mx.transitions.easing.None.easeOut, map._yscale, 275, 2, true);
    function zoomOut(mc:MovieClip) {
        var xs:Tween = new Tween(map, "_xscale", mx.transitions.easing.None.easeOut, mc._xscale, 100, 2, true);
        var ys:Tween = new Tween(map, "_yscale", mx.transitions.easing.None.easeOut, mc._yscale, 100, 2, true);
    It zooms into my map mc when I click on my location 1 mc, but it zooms to the center of my map, is it possible to zoom to certain coordinates rather than the center, basically to zoom to where my location1 mc is
    Thanks

  • Is it possible to unload a program at runtime?

    Hi experts,
    maybe you can help solve the following problem:
    I have a customer program that is calling a sap standard function module several times. The function module is BAPI_BUPA_ADDRESS_ADD. The BAPI works fine when calling it once but I get errors when repeating the call.
    I assume that the error is caused by the fact, that the data of the respective function group is no longer initial after the first call. Of course this would be a programming error. My assumption is approved by a workaround: When I call the function module in a separate work process with "starting new task" I observe no errors.
    Now I wonder if there is a better workaround because starting a new task for each call has the disadvantage of making each call asynchronous - moreover we create many work processes. For example is there a way to unload or refresh a function group at runtime so that the second call is like the first?
    Thanks
    Peter

    Hi Thomas,
    after importing the patch of sap note 1256410 the error "update was terminated", caused by function module BUPA_ADR_WRITE_DOCUMENT due to duplicate entries in table CDPOS, did not appear anymore.
    However calling the function module BAPI_BUPA_ADDRESS_ADD several times destroys the address data of the business partner because the BAPI does not refresh the local address memory. I found out that this can be done with function module BUP_MEMORY_ADDRESS_INIT.
    Thus actually two problems were involved here.
    Peter

  • Possible to access classes in other folders without the use of packages?

    Hi,
    I'm trying to write a kind of connector application, and I have come across this stumbling block.
    I have a folder for my main program classes, which will not change. External to that folder( either in a subdirectory or another directory on the same level) I want to have my classes to "connect". The connected classes will be compiled dynamically, as they depend on something in the main classes folder for complilation... I trust I can satisfy that using javac -classpath...
    The problem is that I would like one of the main classes to be able to access the connected classes at runtime, from the other folder. The collection of connected classes will be changing, so that, coupled with the fact that one of the main classes will be required to compile each connected class seems to rule out the use of packages for the connected classes.
    Is there a way to get around this?
    Thank you,
    Jesse

    Are you trying to dynamically compile Java classes (in external folders
    without packages) via Java? Yes, I will be (hopefully) using com.sun.tools.javac. I haven't done that part yet, as I don't want to waste my time on a design that is fundamentally flawed :)
    Does each new 'application' get placed into its ownfolder? No. I will be building a collection of new apps that will all be contained in one folder.
    Once an application is compiled, must it beimmediately available to the process that compiled
    it? Yes. Once an application is compiled I need it to be accessable from that point on.
    Thanks,
    Jesse

Maybe you are looking for