Changeset 353

Show
Ignore:
Timestamp:
08/25/08 12:55:42 (4 months ago)
Author:
arneke
Message:

Using synchronized code to set expiration header instead of creating new objects all the time. May want an object pool for this.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/geowebcache/src/main/java/org/geowebcache/util/ServletUtils.java

    r317 r353  
    3434 
    3535public class ServletUtils { 
     36    // Calendar objects are unfortunately expensive and not 
     37    // thread safe :( 
     38    static private Calendar calendar = new GregorianCalendar(); 
     39    static private TimeZone timeZone = TimeZone.getTimeZone("GMT"); 
     40    static private SimpleDateFormat format = null; 
     41      
     42     
    3643    /** 
    3744     * Case insensitive lookup 
     
    207214 
    208215    /** 
    209      * Makes HTTP Expire header vaulue 
    210      *   
     216     * Makes HTTP Expire header value 
     217     *  
     218     * Has to be synchronized due to the shared Calendar objects 
     219     *  
    211220     * @param seconds 
    212221     * @return 
    213222     */ 
    214     public static String makeExpiresHeader(int seconds) { 
    215         SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); 
    216         TimeZone timeZone = TimeZone.getTimeZone("GMT"); 
    217         format.setTimeZone(timeZone); 
    218         Calendar calendar = new GregorianCalendar();  
     223    public static synchronized String makeExpiresHeader(int seconds) { 
     224        if(ServletUtils.format == null) { 
     225            ServletUtils.format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); 
     226            ServletUtils.format.setTimeZone(ServletUtils.timeZone); 
     227        } 
    219228         
    220229        calendar.setTimeInMillis(System.currentTimeMillis() + seconds*1000);