Java: finalizer for a class?
<p>I have a class that has a static reference to Spring's ApplicationContext. I need to clear that context and run destroy method of its singleton beans when the class is about to be unloaded. So, is there some class level finalizer callback that is called when the class is unloaded, so I can clear the context in that callback?</p>

<p>I have a vague idea of using WeakReferenceQueue and a counter to keep track of un-referenced objects of that class so I can detect when the class has no live objects, but that still won't tell me when the class itself is unloaded.</p>
