public static Engine getEngine ( String configPath , Properties configProperties ) { if ( StringUtils . isEmpty ( configPath ) ) { configPath = HTTL_PROPERTIES ; } VolatileReference < Engine > reference = ENGINES . get ( configPath ) ; if ( reference == null ) { reference = new VolatileReference < Engine > ( ) ; // quickly VolatileReference < Engine > old = ENGINES . putIfAbsent ( configPath , reference ) ; if ( old != null ) { // duplicate reference = old ; } } assert ( reference != null ) ; Engine engine = reference . get ( ) ; if ( engine == null ) { synchronized ( reference ) { // reference lock engine = reference . get ( ) ; if ( engine == null ) { // double check engine = BeanFactory . createBean ( Engine . class , initProperties ( configPath , configProperties ) ) ; // slowly reference . set ( engine ) ; } } } assert ( engine != null ) ; return engine ; }
Get template engine singleton .