Java Timestamp Format getTimestampFormat()

Here you can find the source of getTimestampFormat()

Description

get Timestamp Format

License

Apache License

Declaration

private static SimpleDateFormat getTimestampFormat() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static final Map<String, ThreadLocal<SimpleDateFormat>> timestampFormatPool = new HashMap<String, ThreadLocal<SimpleDateFormat>>();
    private static final Object timestampFormatLock = new Object();
    private static String timestampPattern = "yyyy-MM-dd HH:mm:ss";

    private static SimpleDateFormat getTimestampFormat() {
        ThreadLocal<SimpleDateFormat> tl = timestampFormatPool.get(timestampPattern);
        if (null == tl) {
            synchronized (timestampFormatLock) {
                tl = timestampFormatPool.get(timestampPattern);
                if (null == tl) {
                    tl = new ThreadLocal<SimpleDateFormat>() {
                        @Override
                        protected synchronized SimpleDateFormat initialValue() {
                            return new SimpleDateFormat(timestampPattern);
                        }/*from   w ww  . j  av  a  2  s  .c o m*/
                    };
                    timestampFormatPool.put(timestampPattern, tl);
                }
            }
        }
        return tl.get();
    }
}

Related

  1. getFormattedTimeStamp(long timestamp, String formatString)
  2. getFullTimestampFormatter(Locale locale)
  3. getTimestamp(boolean useTwentyFourFormat)
  4. getTimeStamp(String format)
  5. getTimestamp(String format)
  6. getTimeStampFormat(Date date)
  7. getTimeStampFormat(Date date)
  8. getTimestampFormat(long time)
  9. sortedTimestampFormat(Date date)