?
Solved

Fast and Thread-Safe Date Formatting

Posted on 2006-05-30
7
Medium Priority
?
529 Views
Last Modified: 2012-05-05
Hi,

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'?

Thanks.
Kalle.
0
Comment
Question by:kalle73
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 16789213
You can make any class instance thread-safe if you wish. Just synchronize access to it
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 16789227
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16798918
Write a wrapper over a SimpleDateFormat:

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

Author Comment

by:kalle73
ID: 16799258
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).
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16799338
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
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

621 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