Fast and Thread-Safe Date Formatting

Posted on 2006-05-30
Last Modified: 2012-05-05

Since SimpleDateFormat is not thread-safe, I'm looking for some fast and thread-safe date formatter. Apache commons (lang) FastDateFormat is great, the problem is that it does 'format' only, while I need both 'format' and 'parse' functionalities.

Can you recommend some reliable, thread-safe and fast date/time formatter supporting 'format' and 'parse'?

Question by:kalle73
    LVL 86

    Accepted Solution

    You can make any class instance thread-safe if you wish. Just synchronize access to it
    LVL 92

    Assisted Solution

    LVL 30

    Expert Comment

    Write a wrapper over a SimpleDateFormat:

    public class MyFormatterParser
      public synchronized String format ( Date d )
        // use SimpleDateFormat here
      // same way create other methods

    Author Comment

    Thanks for the answers. The problem with synchronized/wrapped SimpleDateFormat is that it is very slow. For example apache commons FastDateFormat is way faster (it took 0.5 sec to format 1000000 dates while SimpleDateFormat worked hard for more than 30 sec). Still FastDateFormat doesn't perform parsing and I'm looking for some formatter that does, not being SimpleDateFormat-based (both james and mousepushers are).
    LVL 30

    Expert Comment

    Depends on which way the methods are called. Like if you want to format 100000 dates, you have 2 options:

    1) call format () on your class 100000 times (synchronized method called 100000 times)
    2) write 1 synchronized method which accepts an array of dates, formats them and returns them - might be faster than approach 1

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now