Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6668966

(ref) System.isGarbage(WeakReference) to support deterministic garbage collection for a object

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • None
    • 7
    • core-libs
    • x86
    • windows_2000

      A DESCRIPTION OF THE REQUEST :
      Currently there is no simple way to claim global\shared resources consumed by an instance of a object. There is no guarantee that a finalize will ever execute in an object.

      JUSTIFICATION :
      This enhancement will allow developers to optimize desktop applications meanwhile taking advantages of the built in Garbage Collection

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Add following methods to the java.lang.System class

      //Returns true only and only if the given ref points to object thats not been
      //finalized and can be finalized
       public boolean isGarbage(WeakReference ref) {
        
       }

      //Call finalize on the object the given ref points to only and only if isGarbage()
      //returns true for the given reference. Other wise NoTGrabgeException is //thrown. This method does not gurantee that memory heap used by the object //ref points to, is reclaimed.
       public void finalizeRef(WeakReference ref) throws NotGarbageException {

       }

      ---------- BEGIN SOURCE ----------
      Not the best way to do this just proving a point


      public class ConnectionPool{
        
       private static WeekReference connectionRef_;
       private static Connection connectionSingleton_;
       
       public static Connection get(){
       // blah blah
       }
       
       private static void autoCloseConn(){
        connectionSingleton_=null;
        if(System.isGarbage(connectionRef_))
         System.finalizeRef(connectionRef_);

       }
      }

      public class ConnectionConsumer{
       private void consume(){
       Connection conn =null;
        try{
         conn = ConnectionPool.get();
         //blah blah
        }
        finaly{
           WeekRef ref =conn;
           conn =null;
           if(System.isGarbage(ref))
            System.finalizeRef(ref);

        }
       }

      }

      ---------- END SOURCE ----------

            mr Mark Reinhold
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: