Class WeakTimerTask<T>

  • All Implemented Interfaces:
    java.lang.Runnable

    public abstract class WeakTimerTask<T>
    extends java.util.TimerTask
    This class holds a partner of the TimerTask reference as weak one. This allows to have weak association: the partner's object can be disposed without being blocked by a strong reference of the timer.

    IMPORTANT! Never use this class as base for an inner or anonymous class. This will create an implicit strong reference to the wrapping partner, so it won't be disposed until the timer task is cancelled.

    Author:
    K. Benedyczak
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.ref.WeakReference<T> partnerRef  
    • Constructor Summary

      Constructors 
      Constructor Description
      WeakTimerTask​(T partner)  
    • Method Summary

      • Methods inherited from class java.util.TimerTask

        cancel, run, scheduledExecutionTime
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • partnerRef

        protected java.lang.ref.WeakReference<T> partnerRef
    • Constructor Detail

      • WeakTimerTask

        public WeakTimerTask​(T partner)