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

(ref) Need for a StrongReference class for symmetry with WeakReference?

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.3.1
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: nt126004 Date: 02/01/2002


      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
        Today I was developing a CacheableDocument class, and I
      wanted it to have some flexibility. Turning on/off the
      cache was the main issue; the reference to the document's
      content needs to be either strong (permanent) or weak
      (disposable).

      I thought "Oh, it's simple, let's just use a Reference
      object, and assign a subclass of Reference to it". Wrong!
      There is no StrongReference object... so I will have to
      keep two fields for my document's content: one in case of a
      WeakReference, and another in the case of non-disposable
      String content.

      Clearly, there is a need for a
      java.lang.ref.StrongReference class. Maybe just for the
      sake of completeness, or maybe because some concepts are
      more easily expressed when declaring a
      java.lang.ref.Reference field, and then assigning a
      reference of any strength (strong, soft, weak, phantom) to
      it.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      N/A (enhancement request)


      This bug can be reproduced always.

      CUSTOMER WORKAROUND :
      Declare two fields:
      - java.lang.ref.Reference
      - java.lang.Object
      and assign ONE of the two to your content, depending on
      whether you need permanent or disposable content. This
      requires some extra programming:

      ----

      WeakReference cached;
      Object noncached;

      void setField(Object obj, boolean disposable)
      {
        if(disposable) cached = new WeakReference(obj);
        else noncached = obj;
      }

      Object getField()
      {
        return (cached == null) ? cached : noncached.get();
      }

      ----

      With a StrongReference class, it would be easier:

      Reference ref;

      void setField(Object obj, boolean disposable)
      {
        if(disposable) ref = new WeakReference(obj);
        else ref = new StrongReference(obj);
      }

      Object getField()
      {
        return ref.get();
      }
      (Review ID: 138567)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mr Mark Reinhold
              Reporter:
              nthompsosunw Nathanael Thompson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: