Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: SimpleDateFormat

Frans Verhoef

2005-09-21

Replies:

Hi Richard,
Like someone else already said, you could synchronize access to the DateFormat class. If that is too cumbersome, consider just making local copies of the DateFormat class. The latter option can become quite costly though, if many local copies keep on being created.

Cheers,
Frans

On Wed, 21 Sep 2005 06:57:25 -0700, Richard Yee wrote:
> Frans,
> The DateFormat class is not threadsafe and making only one instance
> of dateFormat for the whole class will cause threading issues. Any
> instance of DateFormat or SimpleDateFormat should be method-local
>
> -Richard
>
> Frans Verhoef wrote:
>> Hi,
>> Make dateFormat a final static variable. This would create only
>> one instance of dateFormat for the whole class.
>>
>> Cheers,
>> Frans
>>
>> On Tue, 20 Sep 2005 17:36:26 -0600, SUBSCRIBE EJB-INTEREST
>> anonymous wrote:
>>
>>> Hi,
>>> Is there a better way to do the below in a multithreaded
>>> application?
>>>
>>> java.text.SimpleDateFormat dateFormat = new
>>> java.text.SimpleDateFormat ("MMddyyyy"); String formatedString
>>> = dateFormat.format(new Date());
>>>
>>> I have the below code within a method in a class.
>>>
>>> Since, an instance of java.text.SimpleDateFormat will be
>>> created for every call of the method, I was wondering this
>>> would create lot of objects in heap.
>>>
>>>
>>> Thanks in advance,
>>>
>>> ======================================================================
>>>  ===== To unsubscribe, send email to listserv@(protected)
>>> include in the body of the message "signoff J2EE-INTEREST".
>>> For general help, send email to listserv@(protected)
>>> include in the body of the message "help".
>>>
>>>
>> ======================================================================
>> ===== To unsubscribe, send email to listserv@(protected)
>> include in the body of the message "signoff J2EE-INTEREST".  For
>> general help, send email to listserv@(protected)
>> the body of the message "help".
>>
>
> ======================================================================
> ===== To unsubscribe, send email to listserv@(protected)
> include in the body of the message "signoff J2EE-INTEREST".  For
> general help, send email to listserv@(protected)
> the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".
©2008 junlu.com - Jax Systems, LLC, U.S.A.