public Object doThreadContextClassLoaderUpdate ( ProceedingJoinPoint pjp ) throws Throwable { final Thread currentThread = Thread . currentThread ( ) ; final ClassLoader previousClassLoader = currentThread . getContextClassLoader ( ) ; Deque < ClassLoader > deque = PREVIOUS_CLASS_LOADER . get ( ) ; if ( deque == null ) { deque = new LinkedList < ClassLoader > ( ) ; PREVIOUS_CLASS_LOADER . set ( deque ) ; } deque . push ( previousClassLoader ) ; try { currentThread . setContextClassLoader ( PORTAL_CLASS_LOADER ) ; return pjp . proceed ( ) ; } finally { currentThread . setContextClassLoader ( previousClassLoader ) ; deque . removeFirst ( ) ; if ( deque . isEmpty ( ) ) { // clean up the threadlocal when the deque is empty PREVIOUS_CLASS_LOADER . remove ( ) ; } } }
Wraps the targeted execution switching the current thread s context class loader to this classes class loader . Usage defined in persistanceContext . xml .