Changeset 3990

Show
Ignore:
Timestamp:
19/10/08 16:11:23 (3 years ago)
Author:
michael
Message:

Make Template Factory? a singleton, not thread-local as this leaks memory.
Fix handling of refresh period to be consistent (milliseconds always).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/java/org/sarugo/xtc/TemplateFactory.java

    r3966 r3990  
    3131public abstract class TemplateFactory { 
    3232 
    33         private static volatile Resolver resolver = new Resolver(); 
     33        private static Resolver resolver = new Resolver(); 
    3434 
    35         private static ThreadLocal<TemplateFactory> instance = new ThreadLocal<TemplateFactory>()
     35        private static TemplateFactory instance
    3636 
    3737        private static final String PROVIDER_RESOURCE = "META-INF/services/org.sarugo.xtc.TemplateFactory"; 
     
    6565 
    6666        /** 
    67          * Contructs a thread-local singleton based on the configured servic
    68          * provider. The provider class is configured in 
     67         * Contructs a singleton based on the configured service provider. Th
     68         * provider class is configured in 
    6969         * <code>META-INF/services/org.sarugo.xtc.TemplateFactory</code>. 
    7070         *  
    71          * @return thread-local singleton. 
     71         * @return singleton. 
    7272         */ 
    73         public static TemplateFactory getInstance() { 
    74                 TemplateFactory result = instance.get(); 
    75                 if (result == null) { 
     73        public static synchronized TemplateFactory getInstance() { 
     74                if (instance == null) { 
    7675                        try { 
    77                                 instance.set((TemplateFactory) Classpath 
    78                                                 .instanceFromConfig(PROVIDER_RESOURCE))
     76                                instance = (TemplateFactory) Classpath 
     77                                                .instanceFromConfig(PROVIDER_RESOURCE)
    7978                        } catch (Exception e) { 
    8079                                throw new RuntimeException( 
     
    8281                                                e); 
    8382                        } 
    84                         result = instance.get(); 
    8583                } 
    86                 if (result == null) { 
     84                if (instance == null) { 
    8785                        throw new RuntimeException( 
    8886                                        "Unable to register the TemplateFactory implementation"); 
    8987                } 
    90                 return result
     88                return instance
    9189        } 
    9290 
     
    9694         * @param resolver 
    9795         */ 
    98         public static void setResolver(Resolver resolver) { 
     96        public static synchronized void setResolver(Resolver resolver) { 
    9997                TemplateFactory.resolver = resolver; 
    10098        } 
    10199 
    102         public static Resolver getResolver() { 
     100        public static synchronized Resolver getResolver() { 
    103101                return resolver; 
    104102        } 
  • trunk/src/main/java/org/sarugo/xtc/impl/DefaultTemplateFactory.java

    r3966 r3990  
    6565        this.templates = new HashMap(); 
    6666        this.relativeLocations = new HashMap(); 
    67         this.refreshPeriod = (refreshPeriod > 0) ? refreshPeriod * 1000 : -1; 
     67        this.refreshPeriod = (refreshPeriod > 0) ? refreshPeriod : -1; 
    6868        log.fine("Using Refresh Period: " + this.refreshPeriod); 
    6969    }