Class WeakThunk<T>

  extended by consciouscode.util.WeakThunk<T>
All Implemented Interfaces:

public class WeakThunk<T>
extends Object
implements Runnable

A Runnable object that uses reflection to invoke a no-argument method on a particular target object, while allowing the target to be garbage-collected. Since a WeakThunk maintains a WeakReference to the target, the target may be garbage collected while the runnable is still accessible. If that happens, the run() method will simply do nothing.

Constructor Summary
WeakThunk(T target, String callbackMethodName)
          Create a new Runnable whose run() method will invoke the named method on the target.
Method Summary
 void run()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public WeakThunk(T target,
                 String callbackMethodName)
          throws IllegalArgumentException,
Create a new Runnable whose run() method will invoke the named method on the target.

target - must not be null.
callbackMethodName - must identify a public no-argument method implemented by target.
IllegalArgumentException - if callbackMethodName does not identify a public no-parameter method on the target object, or if the callback throws any checked exception.
Method Detail


public void run()
Specified by:
run in interface Runnable

Copyright © 2001–2012 Todd V. Jonker. All Rights Reserved.