org.springframework.util
Class WeakReferenceMonitor
java.lang.Object
org.springframework.util.WeakReferenceMonitor
public class WeakReferenceMonitor
- extends Object
Track references to arbitrary objects using proxy and weak references. To
monitor a handle, one should call monitor(Object, ReleaseListener)
,
with the given handle object usually being a holder that uses the target
object underneath, and the release listener performing cleanup of the
target object once the handle is not strongly referenced anymore.
When a given handle becomes weakly reachable, the specified listener
will be called by a background thread. This thread will only be started
lazily and will be stopped once no handles are registered for monitoring
anymore, to be restarted if further handles are added.
Thanks to Tomasz Wysocki for the suggestion and the original
implementation of this class!
- Since:
- 1.2
- Author:
- Colin Sampaleanu, Juergen Hoeller
- See Also:
monitor(java.lang.Object, org.springframework.util.WeakReferenceMonitor.ReleaseListener)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
WeakReferenceMonitor
public WeakReferenceMonitor()
monitor
public static void monitor(Object handle,
WeakReferenceMonitor.ReleaseListener listener)
- Start to monitor given handle object for becoming weakly reachable.
When the handle isn't used anymore, the given listener will be called.
- Parameters:
handle
- the object that will be monitoredlistener
- the listener that will be called upon release of the handle
Copyright © 2002-2008 The Spring Framework.