public static void loadLifecycleHandlers() {
        if (!loadedLock.get()) {
            synchronized (loadedLock) {
                if (!loadedLock.get()) {
                    Set<Class<? extends LifecycleHandler>> subClasses = Reflection.getNonAbstractSubclasses(LifecycleHandler.class);
                    for (Class<? extends LifecycleHandler> clazz : subClasses) {
                        if (clazz.isAnnotationPresent(OnRequest.class)) {
                            private_requestEventHandlers.add(clazz);
                            LOG.info(String.format("preIssueTokenHandler added {%s}", clazz));
                        }
                        if (clazz.isAnnotationPresent(OnResponse.class)) {
                            private_responseEventHandlers.add(clazz);
                            LOG.info(String.format("postIssueTokenHandler added {%s}", clazz));
                        }
                    }
                    Set<Class<? extends ExceptionEventHandler>> exceptionHandlerClasses = Reflection.getNonAbstractSubclasses(ExceptionEventHandler.class);
                    for (Class<? extends ExceptionEventHandler> clazz : exceptionHandlerClasses) {
                        if (clazz.isAnnotationPresent(OnException.class)) {
                            private_exceptionHandlers.add(clazz);
                            LOG.info(String.format("exceptionHandlers added {%s}", clazz));
                        }
                    }
                    loadedLock.set(true);
                }
            }
        }
    }
public static void loadLifecycleHandlers ( ) { if ( ! loadedLock . get ( ) ) { synchronized ( loadedLock ) { if ( ! loadedLock . get ( ) ) { Set < Class < ? extends LifecycleHandler > > subClasses = Reflection . getNonAbstractSubclasses ( LifecycleHandler . class ) ; for ( Class < ? extends LifecycleHandler > clazz : subClasses ) { if ( clazz . isAnnotationPresent ( OnRequest . class ) ) { private_requestEventHandlers . add ( clazz ) ; LOG . info ( String . format ( "preIssueTokenHandler added {%s}" , clazz ) ) ; } if ( clazz . isAnnotationPresent ( OnResponse . class ) ) { private_responseEventHandlers . add ( clazz ) ; LOG . info ( String . format ( "postIssueTokenHandler added {%s}" , clazz ) ) ; } } Set < Class < ? extends ExceptionEventHandler > > exceptionHandlerClasses = Reflection . getNonAbstractSubclasses ( ExceptionEventHandler . class ) ; for ( Class < ? extends ExceptionEventHandler > clazz : exceptionHandlerClasses ) { if ( clazz . isAnnotationPresent ( OnException . class ) ) { private_exceptionHandlers . add ( clazz ) ; LOG . info ( String . format ( "exceptionHandlers added {%s}" , clazz ) ) ; } } loadedLock . set ( true ) ; } } } }
懒加载,并发安全的