protected void preDestroy ( Object instance , final Class < ? > clazz ) throws IllegalAccessException , InvocationTargetException { Class < ? > superClass = clazz . getSuperclass ( ) ; if ( superClass != Object . class ) { preDestroy ( instance , superClass ) ; } // At the end the postconstruct annotated // method is invoked List < AnnotationCacheEntry > annotations = null ; synchronized ( annotationCache ) { annotations = annotationCache . get ( clazz ) ; } if ( annotations == null ) { // instance not created through the instance manager return ; } for ( AnnotationCacheEntry entry : annotations ) { if ( entry . getType ( ) == AnnotationCacheEntryType . PRE_DESTROY ) { Method preDestroy = getMethod ( clazz , entry ) ; synchronized ( preDestroy ) { boolean accessibility = preDestroy . isAccessible ( ) ; preDestroy . setAccessible ( true ) ; preDestroy . invoke ( instance ) ; preDestroy . setAccessible ( accessibility ) ; } } } }
Call preDestroy method on the specified instance recursively from deepest superclass to actual class .