 <p>You could wrap the Thread's <code>Runnable</code> inside another <code>Runnable</code> that would decrement the counter:</p> <pre><code>Thread createThread(final Runnable r) { return new Thread(new Runnable() { @Override public void run() { try { r.run(); } finally { Foo.decrementCounter(); } } }); } </code></pre> <p>The problem with this is if the <code>Runnable r</code> creates multiple instances of Foo. You'd have to somehow track how many instances the thread created. You could do so using a <code>ThreadLocal&lt;Integer&gt;</code>, and then call <code>decrementCounter()</code>, in the <code>finally</code> block, the appropriate number of times. See below for a complete, working example.</p> <p>If you can avoid it, you should not rely on the behavior of the GC as it is quite impredictable! If you insist into dealing with the Garbage Collector, then you should use reference queues -- and to use it properly, you should study the concept of <em>object reachability</em>: <a href="http://docs.oracle.com/javase/7/docs/api/index.html?java/lang/ref/package-summary.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/index.html?java/lang/ref/package-summary.html</a></p> <p>As a final note, if I were interviewing you, I'd try to make you realize that the code you propose does not perfectly satisfy the requirements: you'd have to make the class <code>final</code>, or the method <code>incrementCount()</code> <code>final</code> or <code>private</code>. Or, easier, you could increment the count in an instance initializer block: no need to think about methods being overriden in subclasses or newly added constructors not incrementing the count.</p> <hr> <p>A complete example:</p> <pre><code>public class Foo { private static final AtomicInteger liveInstances = new AtomicInteger(0); private static final ThreadLocal&lt;Integer&gt; threadLocalLiveInstances = new ThreadLocal&lt;Integer&gt;() { @Override protected Integer initialValue() { return 0; } } // instance initializer (so you won't have problems with multiple constructors or virtual methods called from them): { liveInstances.incrementAndGet(); threadLocalLiveInstances.set(threadLocalLiveInstances.get() + 1); } public static int getTotalLiveInstances() { return liveInstances.get(); } public static int getThreadLocalLiveInstances() { return threadLocalLiveInstances.get(); } public static void decrementInstanceCount() { threadLocalLiveInstances.set(threadLocalLiveInstances.get() - 1); liveInstaces.decrementAndGet(); } // ... rest of the code of the class ... } class FooCountingThreadFactory implements ThreadFactory { public Thread newThread(final Runnable r) { return new Thread(new Runnable() { @Override public void run() { try { r.run(); } finally { while (Foo.getThreadLocalLiveInstances() &gt; 0) { Foo.decrementInstanceCount(); } } } }); } } </code></pre> <p>This way, you can feed this ThreadFactory to a thread pool, for example, or you can use it yourself when you want to build a thread: <code>(new FooCountingThreadFactory()).newThread(job);</code></p> <p>Anyways, there's still a problem with this approach: if a thread creates instances of <code>Foo</code> and stores them on global scope (read: <code>static</code> fields), then these instances will still be alive after the thread has died, and the counter will all the same be decremented to 0.</p>