Understanding class unloading

Hi All,
We are using weblogic 7 in our production server and we see lots of _jsp unloadings happening in our servers. This means that, JVM internally unloads these classes so that it can have some room to load some other class.
In our design we use lot of class level variables. Now here are my questions.
1. If JVM has to load the _jsp class again, it has to read 100k of data back (provided the class file is 100k in size).
2. If we use lot of class level variables (static variables), then it will be stored in some part of the heap. If they are primitive types they might get stored in the method area. But if they are objects like hashmaps they will be in some area in the heap and a reference will be there in the method area. If the class is referencing these objects, they will not be GCed.
3. So probably because of this, it is trying to unload the jsp classes?. Is my assumption on point number 2 correct?
4. If it is correct, then probably we may need to reduce the static class variables used in the project.
~Rajesh.B

Hi All,
We are using weblogic 7 in our production server and
d we see lots of _jsp unloadings happening in our
servers. This means that, JVM internally unloads these
classes so that it can have some room to load some
other class.
In our design we use lot of class level variables.
. Now here are my questions.
1. If JVM has to load the _jsp class again, it has to
read 100k of data back (provided the class file is
100k in size).
Loading a class, requires reading the class.
2. If we use lot of class level variables (static
variables), then it will be stored in some part of the
heap. If they are primitive types they might get
stored in the method area. But if they are objects
like hashmaps they will be in some area in the heap
and a reference will be there in the method area. If
the class is referencing these objects, they will not
be GCed.
If an instance of an object does not have a reference then it is collected. If the java.lang.Class instance is collected then the statics will also be collected.
3. So probably because of this, it is trying to unload
the jsp classes?. Is my assumption on point number 2
correct?
Huh? Classes are collected when the class loader is collected. It doesn't have anything to do with statics.
4. If it is correct, then probably we may need to
reduce the static class variables used in the
project.
No, it isn't correct.

Similar Messages

  • Class unloading doesn't work as described in this forum !!!

    Hi,
    to the problem of dynamic class unloading many people in this forum wrote:
    - write your own class loader
    - load the class to be unloaded later
    - set all instances of your own class loader to null
    - if the work is done set all instances of the loaded classes to null
    - call the garbage collector and the classes will be removed
    I constructed a simple test for the problem:
    - the test class
    public class Impl {
    public String getVersion () {
    return "1";
    - instanciating the test class
    - printing the value of getVersion() to the screen
    - changing the return value of getVersion() and recompiling it (the test application is still runnig)
    - unload try (see below)
    - instanciating the test class
    - printing the value of getVersion() to the screen
    Back to the tipps above. Why doing this? The theory says a class loader stores every loaded class for
    suppressing unnecessary reloads. In reality the classes are NOT stored in the own class loader but in
    the parent of it. If no parameter is given to a class loader's constructor the parent of a class loader
    is the system classloader.
    Let's have a look at the source code of java.lang.ClassLoader.loadClass(...):
    protected synchronized Class loadClass(String name, boolean resolve)
    throws ClassNotFoundException
    // First, check if the class has already been loaded
    Class c = findLoadedClass(name);
    if (c == null) {
    try {
    if (parent != null) {
    ### here the loadClass() of the parent is called and the
    ### loaded class is stored within the parent
    c = parent.loadClass(name, false);
    } else {
    c = findBootstrapClass(name);
    } catch (ClassNotFoundException e) {
    // If still not found, then call findClass in order
    // to find the class.
    c = findClass(name);
    if (resolve) {
    resolveClass(c);
    return c;
    My Idea was: Give a null to the class loader's constructor so the classes cannot be stored within a parent.
    Here my test class loader (it is build as it is described within javadoc of java.lang.ClassLoader
    except the constructor):
    import java.io.*;
    public class MyClassLoader extends ClassLoader {
    public MyClassLoader () {
    super ( null );
    public Class findClass ( String name ) {
    byte[] b = loadClassData ( name );
    return defineClass ( name, b, 0, b.length );
    private byte[] loadClassData ( String name ) {
    byte[] ret = null;
    try {
    InputStream in = new FileInputStream ( name + ".class" );
    ret = new byte[in.available ()];
    in.read ( ret );
    } catch ( Exception e ) {
    e.printStackTrace ();
    return ret;
    The loading of the class works fine
    ClassLoader cl = new MyClassLoader ();
    Class c = cl.loadClass ( "Impl" );
    Object i = c.newInstance ();
    Impl impl = (Impl)i;
    The class "Impl" was found and instanciated. But the cast "Impl impl = (Impl)i;" causes a
    "java.lang.ClassCastException: Impl"
    May second idea was deleting all instances of the class to unload from the class loader via reflection.
    A strange way I know but if this is the only way I will do it. But this doesn't work too.
    After deleting the class from the class loader and all its parents the class is still anywhere in the depth
    of the VM.
    Can anybody help me with this problem?
    Thanks in advance,
    Axel.

    <pre>
    I made a similar and simpler program and it worked:
    import java.net.URLClassLoader;
    import java.net.URL;
    public class DynamicExtension {
         public static void main(String args[]) throws Exception {
              URL[] ua = new URL[] {  new URL("file://c:\\TEMP\\") };
              URLClassLoader ucl = new URLClassLoader(ua);
              MyLoadable l =
                   (MyLoadable) ucl.loadClass("LoadableObject").newInstance();
              l.printVersion();
              Thread.currentThread().sleep(10000);
    //you have ten seconds to replace the old version of the LoadableObject.class file
    //so yo?d better had compiled the new one before executing this
              ucl = new URLClassLoader(ua);
              l = (MyLoadable) ucl.loadClass("LoadableObject").newInstance();
              l.printVersion();
              ucl = null;
              l = null;
              System.gc();
    public class LoadableObject implements MyLoadable {
         public void printVersion() {
              System.out.println("version 1");
         protected void finalize() {
              System.out.println("finalizing " + this);
    public interface MyLoadable {     void printVersion();  }
    C:\Java\TIJ2\Test>java DynamicExtension
    version 1
    version 2
    finalizing LoadableObject@1bd03e
    finalizing LoadableObject@4abc9
    The ClassCastException was due to the fact that one class was loaded by the system class loader, the one that appers as Impl impl = (Impl), and the other by MyClassLoader. That mean that they are different for the VM because they are in different namespaces: The namespace for MyClassLoader is the set of classes loaded by itself and those returned to it by his parent class loader as a result of a request to MyClassLoader?s parent class loader to load a class.
    Setting null for the parent of MyClassLoader was in fact the cause of the problem, because that caused a call to a native method called findBoostrapClass. I guess this method looks for the classes in the bootstrap classpath where MyClassLoader shouldn?t be. This causes MyClassLoader loaded the class itself. If MyClassLoader had had the system class loader as its parent the result had been that only one classloader would have loaded the class. This is what happens in the example above so no ClassCastException is thrown.
    In the source code for ClassLoader
    there is the following:
    * The classes loaded by this class loader. The only purpose of this
    * table is to keep the classes from being GC'ed until the loader
    * is GC'ed.
    private Vector classes = new Vector(); /*
    and:
    * Called by the VM to record every loaded class with this loader.
    void addClass(Class c) {
    classes.addElement(c);
    I would like to have seen findLoadedClass checking the already loaded classes in this Vector, but this method is native. Anyway, as the code for loadClass shows, the parent or bootstrap classloader is checked if findLoadedClass doesn?t find the class; Can we guess that findLoadedClass only checks the clases loaded by the classloader, not its parent?
    By the way, could an example like this be made in c++?
    </pre>

  • PermGen not full but full GC triggerred and classes unloaded

    We have a recurring problem where a full GC gets triggered that is quite long (7 seconds). By observation, it seems that a great deal of the full GC time is spent unloading "sun.reflect.GeneratedSerializationConstructorAccessor" classes. However, we have PermSize set to 64 meg and it seems that only 9 megs are actually in use. All the other GCs for the day (about 8.5 hours till the problem) are fairly short (0.10 to 0.35 seconds)
    Any hints as to what is triggering this long GC and how I can avoid it? I know stopping class garbage collection could help, but I am not finding enough information on the risks of doing this. Plus I thought the PermGeneration contained the classes, not the tenured generation.
    Thanks.
    -- 2
    Details
    Solaris 2.8, dual CPU UltraSparc IIIi with 1MB cache each
    8 GB RAM
    Java 1.5.0_06
    Runtime args:
    -Xms1280m -Xmx1280m -server -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+DisableExplicitGC -XX:+PrintGCApplicationStoppedTime -XX:PermSize=64m
    "jmap -h" result (sometime after Full GC):
    Server compiler detected.
    JVM version is 1.5.0_06-b05
    using thread-local object allocation.
    Parallel GC with 2 thread(s)
    Heap Configuration:
    MinHeapFreeRatio = 40
    MaxHeapFreeRatio = 70
    MaxHeapSize = 1342177280 (1280.0MB)
    NewSize = 2228224 (2.125MB)
    MaxNewSize = 4294901760 (4095.9375MB)
    OldSize = 1441792 (1.375MB)
    NewRatio = 2
    SurvivorRatio = 32
    PermSize = 67108864 (64.0MB)
    MaxPermSize = 67108864 (64.0MB)
    Heap Usage:
    PS Young Generation
    Eden Space:
    capacity = 106496000 (101.5625MB)
    used = 24655256 (23.513084411621094MB)
    free = 81840744 (78.0494155883789MB)
    23.151344651442308% used
    From Space:
    capacity = 196608 (0.1875MB)
    used = 134808 (0.12856292724609375MB)
    free = 61800 (0.05893707275390625MB)
    68.56689453125% used
    To Space:
    capacity = 14483456 (13.8125MB)
    used = 0 (0.0MB)
    free = 14483456 (13.8125MB)
    0.0% used
    PS Old Generation
    capacity = 894828544 (853.375MB)
    used = 627750416 (598.6694488525391MB)
    free = 267078128 (254.70555114746094MB)
    70.15315059060075% used
    PS Perm Generation
    capacity = 67108864 (64.0MB)
    used = 9422208 (8.9857177734375MB)
    free = 57686656 (55.0142822265625MB)
    Verbose GC:
    987745K->852246K(1032576K), 0.1995592 secs]
    Total time for which application threads were stopped: 0.2016224 seconds
    24998.391: [GC [PSYoungGen: 153190K->6928K(149952K)] 996182K->859364K(1023808K), 0.1852391 secs]
    Total time for which application threads were stopped: 0.1872944 seconds
    25102.514: [GC [PSYoungGen: 149904K->6384K(156864K)] 1002340K->865912K(1030720K), 0.1630581 secs]
    25102.677: [Full GC[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor7]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor14]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor12]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor10]
    [Unloading class sun.reflect.GeneratedMethodAccessor1]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor8]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor6]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor4]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor2]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor11]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor24]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor21]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor13]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor16]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor9]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor3]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor23]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor1]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor22]
    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor5]
    [PSYoungGen: 6384K->0K(156864K)] [PSOldGen: 859528K->375378K(873856K)] 865912K->375378K(1030720K) [PSPermGen: 9192K->9192K(65536K)], 7.0877752 secs]
    Total time for which application threads were stopped: 7.2531067 seconds
    25210.000: [GC [PSYoungGen: 142016K->5680K(146688K)] 517394K->381058K(1020544K), 0.0708419 secs]

    [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor5 ]
    [PSYoungGen: 6384K->0K(156864K)] [PSOldGen: 859528K->375378K(873856K)] 865912K->375378K(1030720K) [PSPermGen: 9192K->9192K(65536K)], 7.0877752 secs]Despite the messages about unloading classes, it is unlikely that class unloading
    is taking up any significant amount of the 7 seconds. The last line quoted above
    shows the old generation (PSOldGen) had 859528K used before GC and
    375378K used after GC. Reclaiming the ~470MB in the old gen took the
    majority of the time.
    This GC is caused by the fact that your old gen became nearly full, or at least
    full enough that the JVM decided that the next young generation GC would
    fill up the old generation.
    Since you are using 1.5.0_06 you can try using the parallel compacting collector
    to do these Full GCs in parallel. It should reduce the time somewhat if you have 2
    cpus, and even more if you have 4 or more cpus (or hardware threads).
    To enable it, add the option -XX:+UseParallelOldGC.
    If that does not meet your needs or if you have strict limits on GC pause times,
    then you should try using the concurrent collector. See section
    5.4,The Concurrent Low Pause Collector, in the 5.0 tuning guide at
    http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

  • Dynamic class unloading

    i need to re-load / update some dynamically loaded classes. the error code i get when i try
    to load a new version without "unloading" old version:
    Exception in thread "main" java.lang.LinkageError: loader (instance of MyClassLoader): attempted duplicate class definition for name: "net/aaa/bbb/ccc/MyClassName"
    at java.lang.ClassLoader.defineClass1(Native Method)
    i reviewed this page:
    http://blog.taragana.com/index.php/archive/how-to-unload-java-class/
    but it has the phrase:
    After you are done with the class you need to release all references to the class ...
    i do not understand what this means with regards to how reflection works.
    a class cannot know all the objects that it created. but objects have handles their class.
    so what then do you do? create a collection of all objects for no reason other to identify
    the handles pointing to the class object that needs reloading to null ?
    for sure that starting a new jvm can resolve this.
    so this is my technique:
    send message over network to server that causes the server to:
    (1) start a second jvm that is a twin.
    (2) exit, and still have the twin jvm running.
    i have tried something like this:
    machine #1:
    Socket sok = new Socket("192.168.0.2", 5432);
    ObjectOutputStream oos = new ObjectOutputStream(sok.getOutputStream());
    oos.writeObject("/tmp/reboot.exe");
    machine #2:
    Socket sok = serverSocket.accept();
    ObjectInputStream ois = new ObjectInputStream(sok.getInputStream());
    Sting cmd = (String) ois.readObject();
    Runtime rt = Runtime.getRuntime();
    rt.exec(cmd);
    rt.exit(0);*# cat /tmp/reboot.exe*
    +/usr/bin/java Server &+
    note that my executing: */usr/bin/java Server &* works correctly when i type from shell.
    i don't get errors.
    rather, the first jvm exits, and the twin does not seem to start.
    the security risks are a non-issue for me. thanks.
    Edited by: kappa9h on Feb 26, 2008 2:24 AM

    ok. i don't have it working just yet, but the understanding i work in is that a class's
    namespace is not the package name alone. in reality, it is:
    ( net.kappa9h.test.MyClass ) + (class loader)
    in so doing, i can have, in the same jvm , two objects that are instances of :
    net.kappa9h.test.MyClass
    but have different internal logic.
    note:
    i always use same interface.
    and do not need an instance of the original net.kappa9h.test.MyClass to exist at same
    time as updated version of net.kappa9h.test.MyClass .
    note:
    with regard to original response. thank you for this. however, i cannot use timer method. i need to
    allow clients to signal servers to flush their dynamically loaded classes (that are cached), and re-load a newer version from a class server.
    and i don't need to carry state. so i could just start a twin and then commit hara-kiri.
    EDIT: One can not even say c r a p?? What the hell?i don't understand, but i hope i do not post something wrong in original post.
    thanks for assisting in this confounding problem.

  • Need Help in trying to understand class objects

    I need help on understanding following problem.I have two files for that, which are as follows:
    first file
    public class Matrix extends Object {
         private int  matrixData[][];     // integer array to store integer data
         private int    rowMatrix;     // number of rows
         private int    colMatrix;     // number of columns
         public Matrix( int m, int n )
         {       /*Constructor: initializes rowMatrix and colMatrix,
              and creates a double subscripted integer array matrix
              of rowMatrix rows and colMatrixm columns. */
              rowMatrix = m;
              colMatrix = n;
              matrixData = new int[rowMatrix][colMatrix];
         public Matrix( int data[][] )
         {     /* Constructor: creates a double subscripted integer array
              and initilizes the array using values of data[][] array. */
              rowMatrix = data.length;
              colMatrix = data[0].length;
              matrixData = new int [rowMatrix][colMatrix];
              for(int i=0; i<rowMatrix; i++)
                   for(int j=0; j<colMatrix; j++)
                        matrixData[i][j] = data[i][j];
         public int getElement( int i, int j)
         {      /* returns the element at the ith row and jth column of
              this matrix. */
              return matrixData[i][j];
         public boolean setElement( int  x, int i, int j)
         {     /* sets to x the element at the ith row and jth column
              of this matrix; this method  should also check the
              consistency of i and j (i.e.,  if  i and j are in the range
              required for subscripts; only in this situation the operation
              can succeed); the method should return true if the operation
              succeeds, and should return false otherwise.
              for(i=0;i<rowMatrix;i++){
                   for(j=0;j<colMatrix;j++){
                        x = matrixData[i][j];
              if(i<rowMatrix && j<colMatrix){
                   return true;
              else{
                   return false;
         public Matrix transposeMatrix( )
         {     /*returns a reference to an object of the class Matrix,
              that contains the transpose of this matrix. */
         Verify tata;
         Matrix trans;
         //Matrix var = matrixData[rowMatrix][colMatrix];
         for(int row=0;row<rowMatrix;row++){
              for(int col=0;col<colMatrix;col++){
              matrixData[rowMatrix][colMatrix] = matrixData[colMatrix][rowMatrix];
         trans = new Matrix(matrixData);
                         return trans;
         public Matrix multipleMatrix( Matrix m )
              /*returns a reference to an object of the class Matrix,
              that contains the product of this matrix and matrix m. */
          m = new Matrix(matrixData);
              //Matrix var = matrixData[rowMatrix][colMatrix];
              for(int row=0;row<rowMatrix;row++){
                   for(int col=0;col<colMatrix;col++){
                        //trans[row][col] = getElement(row,col);
         return m;
         public int diffMatrix( Matrix m )
              /*returns the sum of the squared element-wise differences
              of this matrix and m ( reference to the formula in the description
              of assignment 5) */
         return 0;
         public String toString(  )
              /* overloads the toString in Object */
              String output = " row = " + rowMatrix + " col="+colMatrix + "\n";
              for( int i=0; i<rowMatrix; i++)
                   for( int j=0; j<colMatrix; j++)
                        output += " " + getElement(i,j) + " ";
                   output += "\n";
              return output;
    Second file
    public class Verify extends Object {
         public static void main( String args[] )
              int[][] dataA = {{1,1,1},{2,0,1},{1,2,0},{4,0,0}}; // data of A
              int[][] dataB = {{1,2,2,0},{1,0,3,0},{1,0,3,4}};   // data of B
              Matrix matrixA = new Matrix(dataA);     // matrix A
              System.out.println("Matrix A:"+matrixA);
              Matrix matrixB = new Matrix(dataB);     // matrix B
              System.out.println("Matrix B:"+matrixB);
              // Calculate the left-hand matrix
              Matrix leftFormula = (matrixA.multipleMatrix(matrixB)).transposeMatrix();
              System.out.println("Left  Side:"+leftFormula);
              // Calculate the right-hand matrix
              Matrix rightFormula = (matrixB.transposeMatrix()).multipleMatrix(matrixA.transposeMatrix());
              System.out.println("Right Side:"+rightFormula);
              // Calculate the difference between left-hand matrix and right-hand matrix
              // according to the formula in assignment description
              double diff = leftFormula.diffMatrix(rightFormula);
              if( diff < 1E-6 ) // 1E-6 is a threshold
                   System.out.println("Formula is TRUE");
              else
                   System.out.println("Formula is FALSE");
    }My basic aim is to verify the formula
    (A . B)' =B' . A' or {(A*B)tranpose = Btranspose * A transpose}Now My problem is that I have to run the verify class file and verify class file will call the matrix class and its methods when to do certain calculations (for example to find left formula it calls tranposematrix() and multipleMatrix();)
    How will I be able to get the matrix which is to be transposed in transposeMatrix method (in Matrix class)becoz in the method call there is no input for transposematrix() and only one input for multipleMatrix(matrix m).
    please peeople help me put in this.
    thanking in advance

    Please don't crosspost.
    http://forum.java.sun.com/thread.jspa?threadID=691969
    The other one is the crosspost.Okay, whatever. I'm not really concerned with which one is the original. I just view the set of threads overall as being a crosspost, and arbitrarily pick one to point others toward.
    But either way
    knightofdurham... pick one thread and post only in
    the one.Indeed. And indicate such in the other one.

  • Java Class unloading

    Can anybody clearly explain when exactly a Java class will be unloaded?
    The scenario is as follows:
    1. Deploy an ear
    2. Access the application using the browser
    3. Re-deploy the ear
    4. Access the same application (same scenario)
    it is observed that no class is unloaded after steps 3 and 4. I guess this should not be the case when a re-deployment happens. Can somebody explain the reason????

    JobAttributes
    public JobAttributes(int copies,
    JobAttributes.DefaultSelectionType defaultSelection,
    JobAttributes.DestinationType destination,
    JobAttributes.DialogType dialog,
    String fileName,
    int maxPage,
    int minPage,
    JobAttributes.MultipleDocumentHandlingType multipleDocumentHandling,
    int[][] pageRanges,
    String printer,
    JobAttributes.SidesType sides)
    Constructs a JobAttributes instance with the specified values for every attribute.
    Parameters
    copies - an integer greater than 0.
    defaultSelection - DefaultSelectionType.ALL, DefaultSelectionType.RANGE, or DefaultSelectionType.SELECTION.
    destination - DesintationType.FILE or DesintationType.PRINTER.
    dialog - DialogType.COMMON, DialogType.NATIVE, or DialogType.NONE.
    fileName - the possibly null file name.
    maxPage - an integer greater than zero and greater than or equal to minPage.
    minPage - an integer greater than zero and less than or equal to maxPage.
    multipleDocumentHandling - MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES or MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES.
    pageRanges - an array of integer arrays of 2 elements. An array is interpreted as a range spanning all pages including and between the specified pages. Ranges must be in ascending order and must not overlap. Specified page numbers cannot be less than minPage nor greater than maxPage. For example: (new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 }, new int[] { 15, 19 } }), specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that (new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }), is an invalid set of page ranges because the two ranges overlap.
    printer - the possibly null printer name.
    sides - SidesType.ONE_SIDED, SidesType.TWO_SIDED_LONG_EDGE, or SidesType.TWO_SIDED_SHORT_EDGE.
    Throws
    IllegalArgumentException if one or more of the above conditions is violated.

  • Very basic noob question about understanding class creation

    After learing some procedural scripting I just started with understanding OOP and have a problem with a basic stuff like this. Why my Try.as below is not working when I type Try(1); in the main file. Output says: Type Coercion failed: cannot convert 1 to Try
    package {
        public class Try {
            public function Try(some:Number) {
                some += 1;
                 trace (some);

    use:
    var s:Try = new Try(3);

  • Understanding class "fingerprints" with SWC files

    I'm sorry for a very poorly structured question. I just run out of English... I hope one of you guess what's the problem and can provide better words to describe it!
    I'm having hard time understanding how classes from SWC files are handled when the app is complied with Flash Builder. We have about 50 SWC files, all compiled from corresponding FLA files. Their libraries contain elements that have AS3 linkages and in the end, there are plenty of classes involved. The classes are packaged in SWC files and Flash Builder finds them just fine. Some AS3 linkages have the same name, which is OK, because they are essentially the same library elements and we don't want to have duplicates in the app. Also plenty of AS3 linkages have same base classes, which means plenty of SWC files carry those base class definitions too, but only one is really needed.
    Sometimes everything works, sometimes something breaks. It almost seems like the moon phase affects whether the end result works or not... Sometimes recompiling SWC files helps with one problem, but breaks something else. This leads me to guess, that Flash Builder selects the available classes based on the date of the SWC files? If more than one SWC files have the same class definition, Flash Builder selects the newest?
    The error we encounter, is "AS3 Error #1034: Type Coercion failed:", which is related to having one of these shared AS3 linkages (let's say SharedClass) on the timeline of a MovieClip. This means it is *not* created with the new keyword! So if SharedClass is defined in SWC1 and SWC2, maybe Flash Builder decides to use the one from SWC1. This means that elements from SWC2 that use SharedClass will use SWC1's definition of it. But for some reason this doesn't always work as it should. It helped, when I changed how AS3 references the instances declared on the timeline: "var mySharedClassObject:SharedClass" --> "var mySharedClassObject:*" but I don't understand why...
    This leads me to believe, that the SharedClass in SWC1 and SWC2 have different "fingerprints" which makes the class casting break in some situations. When I use "new" keyword, everything works, because it doesn't matter which definition will be used. But when the class is created on the timeline, it may require exact fingerprint of that class?
    Most of those cases are easily cleaned, but I'm also running into problems with some classes that have only one definition! If the AS3 linkage of SWC1 has the same base class, than AS3 linkage of SWC2, we run into the same problem. This is because both SWC1 and SWC2 contain the definition of the base class and maybe they have different fingerprints, even though our base classes are just AS3 files (no linkages).
    Does this make any sense?
    Anyone know a way to see the class name collisions and potential problems?

    If different SWC are using exactly the same class, there’s no problem. If more than one is using the same named class, and the two or more copies are different, they it’s down to the order they get compiled, and that can vary.
    Make sure that everywhere that a class has the same name, it’s identical to the other ones. Remember that MovieClips become classes too, so if you have a shared library item named “title”, and it’s different for each SWC because the graphic instead the MovieClip is different, then you’ll get big problems.
    One easy solution is to put the classes into a dedicated folder, like:
    src/com/yourname/game1/Title.as
    and:
    src/com/yourname/game2/Title.as
    instead of:
    src/com/yourname/games/Title.as
    You will end up with a lot of identical things in memory, but they have a different path, and won’t clash with each other.
    Another thing to know, if you use GetDefinitionByName(“class1”), the main document class needs to know about those classes. This will solve that problem:
    public var namedClasses:Array = [class1,class2,class3];
    Then when the compiler is doing its thing, it doesn’t go into shock when an embedded SWC is creating an instance of a class from the shared name.
    So, make sure things are truly identical, or make sure they have a different path.

  • Class unload / reload don't work with JWS

    Hi, I wish to know if it's possible in some way unload an used class and reload a new or changed version of the same class from a jar file with JWS.
    My program has a controling application part that load with a custom classloader the real working classes from a few others jar files.
    Some events make the controling application close and finalize the working classes and download /reload /instantiate the working classes again to get the version.
    This approach work fine when the applicaion is started locally with JAVA.EXE , but when it's started with Java Web Start , don't work.
    Any help or comments will be appreciated.

    Simply don't start the new version, continue to execute the older one until the app exit and JAWS start again.
    I'm sure of release all objects loaded from the actual .jar file, clear cache, download the new .jar , reload the classes , but when they are executed it's the same version.
    No error or complains.
    The aproach to dinamically reload classes it's based in the sample at:
    http://javaalmanac.com/egs/java.lang/ReloadClass.html
    but with a URLClassLoader as parent class.

  • Gc and class unloading

    Question:
    Does the gc mechanism collect unreferenced objects only, or does it also unload classes that serve as blueprint for those unreferenced objects?
    Does anybody know any reference answering this question?

    The problem is that if I load all the classes that I might need unloaded in the future using my custom classloader, and follow the nullifying references/nuking classloader technique, I'll have to nullify all the unloadable objects based on several different classes each time I want to reload one class.
    So I'll need to serialize all those objects, and than reload all the classes loaded/unloaded by the custom classloader, than recreate all the objects from their serialized version.
    And if I create a seperate custom classloader object for each potentially unloadable class, the memory will be crowded.
    So what can I do to reload a class without unloading all the classes loaded by the custom classloader?

  • Class unloading

    Hello,
    When you execute a user-defined class, it is loaded into memory. If you delete or update this class in the file system, and re-execute this class, you get the old version of the class that was previously loaded into memory. Is there a way to get rid of the loaded class so that you get the updated one.
    Thank you

    Allow the classloader that loaded it to be garbage-collectedCould you please expand on that. Also, how can you make a classloader to be garbage-collected ?
    Thank you

  • Understanding class instantiation

    Given classes A, B, and C where B extends A and C extends B and where all classes implement the instance method void doIt(). A reference variable is instantiated as �A x = new B();� and then x.doIt() is executed. What version of the doIt() method is actually executed and why?
    This says to me, I have just created an instance of B of class type A.
    I think class B's doIt() method is the one executed because of that.
    Does anyone have any insight into this?

    A static method can be replaced, which can look like overriding if you don't know the difference.
    For comparison
    public class A {
        public static void main(String[] args) {
            new B().doit(); // prints B.doit() !
            A x = new B();
            x.doit(); // prints A.doit() !
        public static void doit() {
            System.out.println("A.doit()");
    class B extends A {
        public static void doit() {
            System.out.println("B.doit()");

  • Forcing JVM to unload bytecode at runtime, to allow reloading of new class?

    Hi all,
    I would like to know a few things about classes once they are loaded. I believe a loaded class is nothing more than an Object in terms of its lifecycle, correct? If so, then to make a class "unload", you simply have to make sure there are no references to the class correct? So, what are the rules for making sure nothing references a class instance?
    Below I'll list a couple of examples. In Example 1 below, I have class A, B and C. Class A creates a instance variable to class B. In the constructor of class A, it creates a temporary class C, passing to it a reference of itself, which C stores in a local variable. Now, in class C, since it is only created in a Constructor (or method) in class A, it goes out of scope at the end of the method/constructor, and thus its reference to class A is no longer any good, correct? Therefore, at this point, there are no references to class A and thus setting A = null (assuming a "central" class loads class A, B and C like a plugin engine would do) should properly dispose of class A. I know, the GC does NOT necessarily remove the class A bytecode from memory right away. So I guess a question here is in need. When does the class A bytecode actually get removed from the JVM memory, in such a way that a "new" call to create it would effectively tell the JVM to have to open the .class file, read its byte code and create a new instance of it in memory? The purpose of these questions is to figure out how, at runtime to reload a class AND get the actual new version of the code. The reason is, if you do everything possible to unload a class, but the JVM doesn't discard the bytecodes of the class before you tell it to load the same class, it will use the "old" bytecode it has in memory, rather than load the bytecode off the HD or URL location and discard the old bytecode. I need a way to get the JVM to discard the bytecode to reload a newer version of a class. But the reason for the examples below is to also help me understand how a class is actually permitted to be unloaded by the JVM. This is also so that the JVM is not wasting memory with multiple versions of the same class, if it even does that. I want to definitely reclaim any memory used by the older version of the class, before loading a newer version.
    So, in example 2 below, the situation changes slightly. A is now keeping a reference to the class C it creates in the constructor. Because C also creates a reference back to A since the A instance is passed in to C's constructor, A can now not be freed and made available for unloading until the reference to A in C is set to null, is this correct? I seem to lack basic understanding of how the whole reference counting thing works for objects and when a JVM can actually unload the bytecode of an object, thus freeing up memory. I suppose a good book on the JVM would clear this up, but I am hoping one of you reading this will know and can help me understand this process. So in this example, am I correct in that the C reference to A must be set to null, then the A instance must be set to null to tell the JVM there is no more use for the A class? I do realize that if other classes also use A, that the bytecode for A would be kept in memory. Let's assume this is the only use of A, B and C (and looking at the examples, B serves no real purpose anyway, but I already wrote it down so I'll leave it).
    So once again, my goal here is to understand the lifecycle of an object, specifically a Class object (they are one and the same, correct, in terms of lifecycle?), and when the JVM actually removes the bytecode from memory so that if a new version of the same class is now available at runtime, the JVM loads the new bytecode into memory.
    Thanks very much for taking the time to read this and reply.
    Example 1:
    class A
    B b = new B();
    public A()
    C c = new C(this);
    class B
    public B()
    class C
    A a = null;
    public C(A a)
    this.a = a;
    Example 2:
    class A
    B b = new B();
    C c = null;
    public A()
    c = new C(this);
    class B
    public B()
    class C
    A a = null;
    public C(A a)
    this.a = a;
    }

    Cross post (numerous times.)
    http://forum.java.sun.com/thread.jsp?thread=292465&forum=37&message=1152136

  • Please help with simple Classes understanding

    Working further to understand Class formation, and basics.
    At the Java Threads Tutorial site:
    http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    Goal:
    1)To take the following code, and make it into 2 seperate files.
    Reminder.java
    RemindTask.java
    2)Error Free
    Here is the original, functioning code:
    import java.util.Timer;
    import java.util.TimerTask;
    * Simple demo that uses java.util.Timer to schedule a task
    * to execute once 5 seconds have passed.
    * http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    public class Reminder {
        Timer timer;
        public Reminder(int seconds) {
            timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000);
        class RemindTask extends TimerTask {
            public void run() {
                System.out.println("Time's up!");
                timer.cancel(); //Terminate the timer thread
        public static void main(String args[]) {
            new Reminder(5);
            System.out.println("Task scheduled.");
    }Here is what I tried to 2 so far, seperate into 2 seperate files:
    Reminder.java
    package threadspack;    //added this
    import java.util.Timer;
    import java.util.TimerTask;
    * Simple demo that uses java.util.Timer to schedule a task
    * to execute once 5 seconds have passed.
    * http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    public class Reminder {
        Timer timer;
        public Reminder(int seconds) {
            timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000);
        public static void main(String args[]) {
            new Reminder(5);
            System.out.println("Task scheduled.");
    }and into
    RemindTask.java
    package threadspack;  //added this
    import java.util.Timer;
    import java.util.TimerTask;
    import threadspack.Reminder; //added this
    * http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
    public class RemindTask extends TimerTask
    Timer timer; /**here, I added this, because got a
    "cannot resolve symbol" error if try to compile w/out it
    but I thought using packages would have negated the need to do this....?*/
         public void run() {
                System.out.println("Time's up!");
                timer.cancel(); //Terminate the timer thread
    }After executing Reminder, the program does perform, even does the timing, however, a NullPointerException error is thrown in the RemindTask class because of this line:
    timer.cancel(); //Terminate the timer thread
    I am not sure of:
    If I have packages/import statements setup correctly
    If I have the "Timer" variable setup incorrectly/wrong spot.
    ...how to fix the problem(s)
    Thank you!

    Hi there!
    I understand that somehow the original "Timer" must
    be referenced.
    This is a major point of confusion for me....I
    thought that when importing
    Classes from the same package/other packages, you
    would have directly
    access to the variables within the imported Classes.I think you have one of the basic points of confussion. You are mixing up the concept of a "Class" with the concept of an "Object".
    Now, first of all, you do not need packages at all for what you are trying to do, so my advice is you completely forget about packages for the moment, they will only mess you up more. Simply place both .class files (compiled .java files) in the same directory. Your program is executing fine, so that indicates that the directory in which you have your main class file is being included in your classpath, so the JVM will find any class file you place there.
    As for Classes/Objects, think of the Class as the map in which the structure of a building is designed, and think of the Object as the building itself. Using the same technical map the architect defines, you could build as many buildings as you wanted. They could each have different colors, different types of doors, different window decorations, etc... but they would all have the same basic structure: the one defined in the technical map. So, the technical map is the Class, and each of the buildings is an object. In Java terminology, you would say that each of the buildings is an "Instance" of the Class.
    Lets take a simpler example with a class representing icecreams. Imagine you code the following class:
    public class Icecream{
         String flavor;
         boolean hasChocoChips;
    }Ok, with this code, what you're doing is defining the "structure" of an icecream. You can see that we have two variables in our class: a String variable with the description of the icecream's flavor, and a boolean variable indicating whether or not the icecream has chocolate chips. However, with that code you are not actually CREATING those variables (that is, allocating memory space for that data). All you are doing is saying that EACH icecream which is created will have those two variables. As I mentioned before, in Java terminology, creating an icecream would be instantiating an Icrecream object from the Icecream class.
    Ok, so lets make icrecream!!!
    Ummm... Why would we want to make several icecreams? Well, lets assume we have an icecream store:
    public class IcecreamStore{
    }Now, we want to sell icecreams, so lets put icecreams in our icecream store:
    public class IcecreamStore{
         Icecream strawberryIcecream = new Icecream(); //This is an object, it's an instance of Class Icecream
         Icecream lemonIcecream = new Icecream(); //This is another object, it's an instance of Class Icecream
    }By creating the two Icecream objects you have actually created (allocated memory space) the String and boolean variable for EACH of those icecreams. So you have actually created two String variables and two boolean variables.
    And how do we reference variables, objects, etc...?
    Well, we're selling icecreams, so lets create an icecream salesman:
    public class IcecreamSalesMan{
    }Our icecream salesman wants to sell icecreams, so lets give him a store. Lets say that each icecream store can only hold 3 icecreams. We could then define the IcecreamStore class as follows:
    public class IcecreamStore{
         Icecream icecream1;
         Icecream icecream2;
         Icecream icecream3;
    }Now lets modify our IcecreamSalesMan class to give the guy an icecream store:
    public class IcecreamSalesMan{
         IcecreamStore store = new IcecreamStore();
    }Ok, so now we have within our IcecreamSalesMan class a variable, called "store" which is itself an object (an instance) of the calss IcecreamStore.
    Now, as defined above, our IcecreamStore class will have three Icecream objects. Indirectly, our icecream salesman has now three icecreams, since he has an IcecreamStore object which in turn holds three Icecream objects.
    On the other hand, our good old salesman wants the three icecreams in his store to be chocolate, strawberry, and orange flavored. And he wants the two first icecreams to have chocolate chips, but not the third one. Well, here's the whole thing in java language:
    public class Icecream{ //define the Icecream class
         String flavor;
         boolean hasChocoChips;
    public class IcecreamStore{ //define the IcecreamStore class
         //Each icecream store will have three icecreams
         Icecream icecream1 = new Icecream(); //Create an Icecream object
         Icecream icecream2 = new Icecream(); //Create another Icecream object
         Icecream icecream3 = new Icecream(); //Create another Icecream object
    public class IcecreamSalesMan{ //this is our main (executable) class
         IcecreamStore store; //Our class has a variable which is an IcecreamStore object
         public void main(String args[]){
              store = new IcecreamStore(); //Create the store object (which itself will have 3 Icecream objects)
              /*Put the flavors and chocolate chips:*/
              store.icecream1.flavor = "Chocolate"; //Variable "flavor" of variable "icecream1" of variable "store"
              store.icecream2.flavor = "Strawberry"; //Variable "flavor" of variable "icecream2" of variable "store"
              store.icecream3.flavor = "Orange";
              store.icecream1.hasChocoChips = true;
              store.icecream2.hasChocoChips = true;
              store.icecream3.hasChocoChips = false;
    }And, retaking your original question, each of these three classes (Icecream, IcecreamStore, and IcecreamSalesMan) could be in a different .java file, and the program would work just fine. No need for packages!
    I'm sorry if you already knew all this and I just gave you a stupid lecture, but from your post I got the impression that you didn't have these concepts very clear. Otherwise, if you got the point, I'll let your extrapolate it to your own code. Should be a pice of cake!

  • GC performance and Class Loading/Unloading

    We have EP 6.0, SP11 on Solaris with JDK 1.4.8_02. We are running Web Dynpro version of MSS/ESS and Adobe Document Services. This is a Java stack only Web AS.
    We are experiencing very uneven performance on the Portal. Usually, when the Portal grinds to a halt, the server log shows GC entries or Class unloading entries for the entire time the Portal stops working.
    I am thinking about setting the GC parameters to the same size to try and eliminate sudden GC interruptions. Also, what parameter can I set to allow as many classes to be loaded at startup and stay in memory for as long as possible?
    Thanks,
    Rob Bartlett

    Hi Robert
    Also, if the host running the WebAS is a multi processor machine, then setting the flags
    -XX:+UseConcMarkSweepGC and
    -XX:+UseParNewGC
    will help reduce the pause time during the GC collection in old generation and the young genereation respectively, as the GC will happen using multiple threads
    I can suggest you to check if the GC performs a minor collection or major collection by enabling the flags
    -verbose:gc   
    -XX:+PrintGCTimeStamps   
    -XX:+PrintGCDetails. Based on this, try to tune the young or old generation.
    Regards
    Madhu

Maybe you are looking for

  • Report S_ALR_87011964 Asset balances does not match AW01N

    In march 08, useful life of one asset is reduced to 4.4 years effective Mar 08. Accordingly - system has revised Plan Deprn figures from march 08 to through Dec 08 & planned book value is nil as at Dec 08(These calculationa are perfect). Then Deprn r

  • In -App purchase With the absence of live app

    Hi, I am developing an application which features 'in-app purchases'. But i heard that a live app should be there in app store for this feature , currently i dont have any live application in app store.Anybody have an idea that to get in -app purchas

  • Web Server 7.0 update 8 and Web Server 6.1 SP12 have been released

    We are delighted to announce that Web Server 7.0 Update 8 has been released. It can be publicly downloaded at: [http://tiny.cc/9Qx1N] The Release Notes is here: [http://docs.sun.com/app/docs/doc/821-1403] This release mainly addresses critical securi

  • Which version of OCCI for Oracle XE 10.2?

    Hi, I have Oracle XE, Linux version 10.2.0.1 installed. I want to connect my C++ application running on the same machine as the database. I've seen lots of dire warnings about the importance of making sure that the right versions are installed, but a

  • Difference between javac and eclipse compiler

    I have the following code: public class Test {      public static void main(String[] args) {                     Integer i = 0;           double d = 1.5d;           i += d;           System.out.println(i); }javac gives me the following error: Test.ja