Java Date Format Pattern getPooledSDF(String format)

Here you can find the source of getPooledSDF(String format)

Description

Gets a SimpleDateFormat for the given format.

License

Open Source License

Parameter

Parameter Description
format The format

Return

The SimpleDateFormat object

Declaration

protected static SimpleDateFormat getPooledSDF(String format) 

Method Source Code


//package com.java2s;
//  in accordance with the terms of the license agreement accompanying it.

import java.text.SimpleDateFormat;

import java.util.EmptyStackException;

import java.util.Hashtable;

import java.util.Stack;

public class Main {
    protected static Hashtable sdfCache = new Hashtable();

    /**//  w  w  w .ja  v  a 2  s.c  o m
     * <p>Gets a SimpleDateFormat for the given format. SimpleDateFormat objects
     * are cached for performance and locking reasons
     * @param format The format
     * @return The SimpleDateFormat object
     */
    protected static SimpleDateFormat getPooledSDF(String format) {
        SimpleDateFormat sdf = null;

        Stack stack = (Stack) sdfCache.get(format);
        if (stack != null) {
            try {
                sdf = (SimpleDateFormat) stack.pop();
            } catch (EmptyStackException ese) {
                // Ignore - create below
            }
        }

        // Either this is the first time we've requested this format or all
        // of the objects are being used; create a new one
        if (sdf == null) {
            sdf = new SimpleDateFormat(format);
        }
        return sdf;
    }
}

Related

  1. getMM(String strDate)
  2. getMMdd()
  3. getMMDDYYHHMM()
  4. getMMDDYYYY(final Date date, final String separator)
  5. getMomentFormatter()
  6. getSdf(String formatPattern)
  7. getSimpleDataFormattedFile(File file)
  8. getSortedTimetampFormat()
  9. getStringAcordFormat()