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

java.lang.ref.SoftReference: Add a timeout attribute

    XMLWordPrintable

    Details

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

      Description



      Name: bk70084 Date: 07/13/98

      Let say one have a very big array which can be computed in about 10 seconds
      (for example the result of some kind of spectral analysis). Let say one need
      this array often (for example each time a component is draw). In my
      understanding of the java.lang.ref package, the SoftReference class is perfect
      for that, since it is always possible to recompute this array if it as been
      garbage collected for memory reasons.

      Now there is my problem: Let say the user is working on an other component
      which hide the first one. The big array may not be need for one hour. It make
      sense to me to keep this array if it is often used. But does it make sense to
      keep for many hours an unused array which can be recomputed in 10 seconds? I
      know almost nothing about operating system, but it seem to me that some
      operation systems may begin to swap memory on the hard drive before the
      SoftReference class get a MemoryAdvice. YELLOW advice. In this case, the
      unused big array will be really slowing down the system instead of making it
      faster.

      My suggestion would be to add one method to the SoftReference class:

          setTimeout(int nmillis)

      If nmillis seconds are elapsed since the last call to the get method, then
      SoftReference may clear this reference. Each time the get method is called, the
      count of elapsed time is reset to zero. So if a big object is not use for, say,
      one hour, it may be cleared and his memory used for other task.

      I see an other advantage: when SoftReference get a MemoryAdvice.YELLOW advice,
      it may use this information to choose which references to clear first. For
      example if the reference A has a timeout of 3 minutes and the reference B has a
      timeout of 1 minute, and if 2 minutes 45 seconds have been elapsed since the
      last A.get() call and only 25 seconds since the last B.get() call, then the
      SoftReference class will try to clear A before B (because A would timeout in 15
      seconds and B in 35 seconds).

      Anyway, I don't know if it is reasonable to implement. Thank for listening.


      (Review ID: 34962)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            mr Mark Reinhold
            Reporter:
            bklocksunw Brian Klock (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: