System.out.println("the date");
You couldn't leave a door like that open and not expect some to walk through it now could you...
SimpleDateFormat is quit fast enough... just don't create a new date formatter everytime you format a date... and it says so in the manual.
Keith.
RTFJD:
http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
Synchronization
Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
> Depends how good you are. :-)
True... and if the OP needs to ask a question like this, then maybe I should take back the suggestion that the OP will be able to come up with a faster soluton.
Of course we can't even answer the OP's question as posted since we don't even know the requirement.
> But SimpleDateFormat is not thread safe.
> Synchronization
>
> Date formats are not synchronized. It is recommended
> to create separate format instances for each thread.
> If multiple threads access a format concurrently, it
> must be synchronized externally.
If you want to have one SimpleDateFormat per thread, consider ThreadLocal. That's what it's for.
> At times when we declare formatter again and again,
> the SimpleDateFormat's performance is less as
> compared to the apache's FastDateFormat..
1) Decaring it wouldn't be what makes it slow. Instantiating it would.
2) As already stated--simply don't instantiate that many of them. Create a few and reuse them.
3) So what if the other one is faster? Have you run into actual problems with SimpleDateFormat being a bottleneck? A Ferrari is faster than my car, but it makes no significant difference for how I use a car. I would not realize any meaningful speed improvement if I had a Ferrari.
4) If the other one is faster and it's that buggerall important, then use the faster one.
>. So I was
> trying to find out if Sun has something to solve my
> problem.
You can peruse the API docs as well as anybody else.
> I am using the formatting in batch process
> so data to process is huge.
Have you found a bottleneck? Have you put a profiler on it? Have you determined that it's the parsing that's causing the problems and that creating is negligible?