You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by bt...@neteverything.com on 2005/05/27 23:03:35 UTC

Re: Date Formatter - not thread safe

SimpleDateFormat is not thread safe.  You will get weird behavior under
high concurrency.

It cannot be static in the Global, you do have the following options:

1) make the pattern static in Global, and do a new SimpleDateFormat for
each get.

2) make the SimpleDateFormat static in Visit, since you can be assured for
the most part that it will not be accessed by multiple threads at once.

Ben

> Thanks - worked like a charm.
>
> Patrick
>
> Jamie Orchard-Hays wrote:
>
>> You could put your format strings in your Visit or Global object:
>>
>>
>> private static final SimpleDateFormat SHORT_DATETIME_FORMAT = new
>> SimpleDateFormat("MM/dd/yy h:mm a");
>> private static final SimpleDateFormat DEADLINE_DATETIME_FORMAT = new
>> SimpleDateFormat("EEEE, MMMM d, yyyy @ h:mm a");
>>
>> Then make getters so your ognl reference isn't hideously long:
>> public Format getShortDatetimeFormat(){
>>    return SHORT_DATETIME_FORMAT;
>> }
>> public Format getDeadlineDatetimeFormat() {
>>     return DEADLINE_DATETIME_FORMAT;
>> }
>>
>> and then use them in your ognl expression:
>>
>> <component id="jobResumeDeadline" type="common:Write">
>>     <binding name="value" expression="job.resumeDueDate"/>
>>     <binding name="format" expression="visit.deadlineDatetimeFormat"/>
>> </component>
>>
>> (common:Write) is our own customized version of Insert)
>>
>> Patrick Kelly wrote:
>>
>>> I have a date originally set as "new
>>> java.sql.Timestamp(time.getTime()" to my DB.  I retrieve the data in
>>> string format such as "2005-05-13 12:10:57.0" and I am able to bind
>>> it with no problem.  However, I need to format the date such as "MMM
>>> dd, yy, HH:mm:ss" in the binding of a table model.  I would rather do
>>> the formatting within the .page file than in a .java file.
>>>
>>> Any help would be appreciated,
>>> Thanks - Patrick
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
> --
> Patrick Kelly
> E-Learning Consultant
> Learning Commons, University of Calgary
> http://commons.ucalgary.ca
> Phone: 220-2547
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Date Formatter - not thread safe

Posted by Jijoe Vurghese <ji...@yahoo.com>.
Benjamin Tomasini <btomasini <at> neteverything.com> writes:

> Is there a way to expose a java.text.Format through it?  I think that is 
> what Tapestry needs.

I doubt we'd get a java.text.Format from this library. Alternatively, this
library provides DateTimeFormat ( http://tinyurl.com/73lm3 ) which is
thread-safe and provides similar or more functionality than java.text.Format.

I'm not too familiar with the Table component (haven't used it yet), but I
would've thought the Table model (provides the data behind the Table component)
lets you specify any class to render a column. Maybe I am oversimplifying.

Jijoe




---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Date Formatter - not thread safe

Posted by Benjamin Tomasini <bt...@neteverything.com>.
This is a great library.

Is there a way to expose a java.text.Format through it?  I think that is 
what Tapestry needs.

Ben

Jijoe Vurghese wrote:

>Or how about a thread-safe alternative (it is free and open-source). 
>
>http://joda-time.sourceforge.net/
>
>I've been using this library quite successfully.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Date Formatter - not thread safe

Posted by Jijoe Vurghese <ji...@yahoo.com>.
Or how about a thread-safe alternative (it is free and open-source). 

http://joda-time.sourceforge.net/

I've been using this library quite successfully.


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Date Formatter - not thread safe

Posted by Scott Morgan <mo...@gmail.com>.
jakarta commons FastDateFormat is thread-safe

http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/time/FastDateFormat.html

On 5/29/05, Erik Hatcher <er...@ehatchersolutions.com> wrote:
> 
> On May 29, 2005, at 2:04 PM, Jamie Orchard-Hays wrote:
> 
> > Yeah, I'd forgotten that. I'm sure it's why we put these in our
> > Visit class.
> 
> The idea (in the Darden design) to use a hard-coded data format, but
> in a Visit-centric way so that in the future if you wanted to provide
> Locale-specific handling it could be done on a per-Visit basis.
> 
>      Erik
> 
> 
> >
> > Jamie
> >
> >
> > On May 27, 2005, at 5:03 PM, btomasini@neteverything.com wrote:
> >
> >
> >> SimpleDateFormat is not thread safe.  You will get weird behavior
> >> under
> >> high concurrency.
> >>
> >> It cannot be static in the Global, you do have the following options:
> >>
> >> 1) make the pattern static in Global, and do a new
> >> SimpleDateFormat for
> >> each get.
> >>
> >> 2) make the SimpleDateFormat static in Visit, since you can be
> >> assured for
> >> the most part that it will not be accessed by multiple threads at
> >> once.
> >>
> >> Ben
> >>
> >>
> >>> Thanks - worked like a charm.
> >>>
> >>> Patrick
> >>>
> >>> Jamie Orchard-Hays wrote:
> >>>
> >>>
> >>>> You could put your format strings in your Visit or Global object:
> >>>>
> >>>>
> >>>> private static final SimpleDateFormat SHORT_DATETIME_FORMAT = new
> >>>> SimpleDateFormat("MM/dd/yy h:mm a");
> >>>> private static final SimpleDateFormat DEADLINE_DATETIME_FORMAT =
> >>>> new
> >>>> SimpleDateFormat("EEEE, MMMM d, yyyy @ h:mm a");
> >>>>
> >>>> Then make getters so your ognl reference isn't hideously long:
> >>>> public Format getShortDatetimeFormat(){
> >>>>    return SHORT_DATETIME_FORMAT;
> >>>> }
> >>>> public Format getDeadlineDatetimeFormat() {
> >>>>     return DEADLINE_DATETIME_FORMAT;
> >>>> }
> >>>>
> >>>> and then use them in your ognl expression:
> >>>>
> >>>> <component id="jobResumeDeadline" type="common:Write">
> >>>>     <binding name="value" expression="job.resumeDueDate"/>
> >>>>     <binding name="format"
> >>>> expression="visit.deadlineDatetimeFormat"/>
> >>>> </component>
> >>>>
> >>>> (common:Write) is our own customized version of Insert)
> >>>>
> >>>> Patrick Kelly wrote:
> >>>>
> >>>>
> >>>>> I have a date originally set as "new
> >>>>> java.sql.Timestamp(time.getTime()" to my DB.  I retrieve the
> >>>>> data in
> >>>>> string format such as "2005-05-13 12:10:57.0" and I am able to
> >>>>> bind
> >>>>> it with no problem.  However, I need to format the date such as
> >>>>> "MMM
> >>>>> dd, yy, HH:mm:ss" in the binding of a table model.  I would
> >>>>> rather do
> >>>>> the formatting within the .page file than in a .java file.
> >>>>>
> >>>>> Any help would be appreciated,
> >>>>> Thanks - Patrick
> >>>>>
> >>>>>
> >>>>> ------------------------------------------------------------------
> >>>>> ---
> >>>>> To unsubscribe, e-mail: tapestry-user-
> >>>>> unsubscribe@jakarta.apache.org
> >>>>> For additional commands, e-mail: tapestry-user-
> >>>>> help@jakarta.apache.org
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>> -------------------------------------------------------------------
> >>>> --
> >>>> To unsubscribe, e-mail: tapestry-user-
> >>>> unsubscribe@jakarta.apache.org
> >>>> For additional commands, e-mail: tapestry-user-
> >>>> help@jakarta.apache.org
> >>>>
> >>>>
> >>>
> >>> --
> >>> Patrick Kelly
> >>> E-Learning Consultant
> >>> Learning Commons, University of Calgary
> >>> http://commons.ucalgary.ca
> >>> Phone: 220-2547
> >>>
> >>>
> >>> --------------------------------------------------------------------
> >>> -
> >>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail: tapestry-user-
> >>> help@jakarta.apache.org
> >>>
> >>>
> >>>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: tapestry-user-
> >> help@jakarta.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Date Formatter - not thread safe

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On May 29, 2005, at 2:04 PM, Jamie Orchard-Hays wrote:

> Yeah, I'd forgotten that. I'm sure it's why we put these in our  
> Visit class.

The idea (in the Darden design) to use a hard-coded data format, but  
in a Visit-centric way so that in the future if you wanted to provide  
Locale-specific handling it could be done on a per-Visit basis.

     Erik


>
> Jamie
>
>
> On May 27, 2005, at 5:03 PM, btomasini@neteverything.com wrote:
>
>
>> SimpleDateFormat is not thread safe.  You will get weird behavior  
>> under
>> high concurrency.
>>
>> It cannot be static in the Global, you do have the following options:
>>
>> 1) make the pattern static in Global, and do a new  
>> SimpleDateFormat for
>> each get.
>>
>> 2) make the SimpleDateFormat static in Visit, since you can be  
>> assured for
>> the most part that it will not be accessed by multiple threads at  
>> once.
>>
>> Ben
>>
>>
>>> Thanks - worked like a charm.
>>>
>>> Patrick
>>>
>>> Jamie Orchard-Hays wrote:
>>>
>>>
>>>> You could put your format strings in your Visit or Global object:
>>>>
>>>>
>>>> private static final SimpleDateFormat SHORT_DATETIME_FORMAT = new
>>>> SimpleDateFormat("MM/dd/yy h:mm a");
>>>> private static final SimpleDateFormat DEADLINE_DATETIME_FORMAT =  
>>>> new
>>>> SimpleDateFormat("EEEE, MMMM d, yyyy @ h:mm a");
>>>>
>>>> Then make getters so your ognl reference isn't hideously long:
>>>> public Format getShortDatetimeFormat(){
>>>>    return SHORT_DATETIME_FORMAT;
>>>> }
>>>> public Format getDeadlineDatetimeFormat() {
>>>>     return DEADLINE_DATETIME_FORMAT;
>>>> }
>>>>
>>>> and then use them in your ognl expression:
>>>>
>>>> <component id="jobResumeDeadline" type="common:Write">
>>>>     <binding name="value" expression="job.resumeDueDate"/>
>>>>     <binding name="format"  
>>>> expression="visit.deadlineDatetimeFormat"/>
>>>> </component>
>>>>
>>>> (common:Write) is our own customized version of Insert)
>>>>
>>>> Patrick Kelly wrote:
>>>>
>>>>
>>>>> I have a date originally set as "new
>>>>> java.sql.Timestamp(time.getTime()" to my DB.  I retrieve the  
>>>>> data in
>>>>> string format such as "2005-05-13 12:10:57.0" and I am able to  
>>>>> bind
>>>>> it with no problem.  However, I need to format the date such as  
>>>>> "MMM
>>>>> dd, yy, HH:mm:ss" in the binding of a table model.  I would  
>>>>> rather do
>>>>> the formatting within the .page file than in a .java file.
>>>>>
>>>>> Any help would be appreciated,
>>>>> Thanks - Patrick
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------ 
>>>>> ---
>>>>> To unsubscribe, e-mail: tapestry-user- 
>>>>> unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: tapestry-user- 
>>>>> help@jakarta.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>> ------------------------------------------------------------------- 
>>>> --
>>>> To unsubscribe, e-mail: tapestry-user- 
>>>> unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: tapestry-user- 
>>>> help@jakarta.apache.org
>>>>
>>>>
>>>
>>> --
>>> Patrick Kelly
>>> E-Learning Consultant
>>> Learning Commons, University of Calgary
>>> http://commons.ucalgary.ca
>>> Phone: 220-2547
>>>
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user- 
>>> help@jakarta.apache.org
>>>
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user- 
>> help@jakarta.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Date Formatter - not thread safe

Posted by Jamie Orchard-Hays <ja...@dang.com>.
Yeah, I'd forgotten that. I'm sure it's why we put these in our Visit  
class.

Jamie


On May 27, 2005, at 5:03 PM, btomasini@neteverything.com wrote:

> SimpleDateFormat is not thread safe.  You will get weird behavior under
> high concurrency.
>
> It cannot be static in the Global, you do have the following options:
>
> 1) make the pattern static in Global, and do a new SimpleDateFormat for
> each get.
>
> 2) make the SimpleDateFormat static in Visit, since you can be assured  
> for
> the most part that it will not be accessed by multiple threads at once.
>
> Ben
>
>> Thanks - worked like a charm.
>>
>> Patrick
>>
>> Jamie Orchard-Hays wrote:
>>
>>> You could put your format strings in your Visit or Global object:
>>>
>>>
>>> private static final SimpleDateFormat SHORT_DATETIME_FORMAT = new
>>> SimpleDateFormat("MM/dd/yy h:mm a");
>>> private static final SimpleDateFormat DEADLINE_DATETIME_FORMAT = new
>>> SimpleDateFormat("EEEE, MMMM d, yyyy @ h:mm a");
>>>
>>> Then make getters so your ognl reference isn't hideously long:
>>> public Format getShortDatetimeFormat(){
>>>    return SHORT_DATETIME_FORMAT;
>>> }
>>> public Format getDeadlineDatetimeFormat() {
>>>     return DEADLINE_DATETIME_FORMAT;
>>> }
>>>
>>> and then use them in your ognl expression:
>>>
>>> <component id="jobResumeDeadline" type="common:Write">
>>>     <binding name="value" expression="job.resumeDueDate"/>
>>>     <binding name="format"  
>>> expression="visit.deadlineDatetimeFormat"/>
>>> </component>
>>>
>>> (common:Write) is our own customized version of Insert)
>>>
>>> Patrick Kelly wrote:
>>>
>>>> I have a date originally set as "new
>>>> java.sql.Timestamp(time.getTime()" to my DB.  I retrieve the data in
>>>> string format such as "2005-05-13 12:10:57.0" and I am able to bind
>>>> it with no problem.  However, I need to format the date such as "MMM
>>>> dd, yy, HH:mm:ss" in the binding of a table model.  I would rather  
>>>> do
>>>> the formatting within the .page file than in a .java file.
>>>>
>>>> Any help would be appreciated,
>>>> Thanks - Patrick
>>>>
>>>>
>>>> -------------------------------------------------------------------- 
>>>> -
>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:  
>>>> tapestry-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:  
>>> tapestry-user-help@jakarta.apache.org
>>>
>>
>> --
>> Patrick Kelly
>> E-Learning Consultant
>> Learning Commons, University of Calgary
>> http://commons.ucalgary.ca
>> Phone: 220-2547
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Date Formatter - not thread safe

Posted by Patrick Casey <pa...@adelphia.net>.
	Aren't you still going to have a wee bit of a race condition if you
stash it in the visit? The user could push two links in rapid succession,
resulting in two parallel threads both operating against the same session
(and hence visit object)?

	Wouldn't you be better off spawning a new one on demand e.g.

	Public Form getDeadlineDatetimeFormat() {
		SimpledateFormat rc = new SimpleDateFormat("MM/dd/yy h:mm
a");
		Return rc;
	}

	Date Format's aren't particularly expensive so I don't think
creating a new one per page render is going to be problematic.

	--- Pat

> -----Original Message-----
> From: btomasini@neteverything.com [mailto:btomasini@neteverything.com]
> Sent: Friday, May 27, 2005 2:04 PM
> To: Tapestry users
> Cc: Tapestry users
> Subject: Re: Date Formatter - not thread safe
> 
> SimpleDateFormat is not thread safe.  You will get weird behavior under
> high concurrency.
> 
> It cannot be static in the Global, you do have the following options:
> 
> 1) make the pattern static in Global, and do a new SimpleDateFormat for
> each get.
> 
> 2) make the SimpleDateFormat static in Visit, since you can be assured for
> the most part that it will not be accessed by multiple threads at once.
> 
> Ben
> 
> > Thanks - worked like a charm.
> >
> > Patrick
> >
> > Jamie Orchard-Hays wrote:
> >
> >> You could put your format strings in your Visit or Global object:
> >>
> >>
> >> private static final SimpleDateFormat SHORT_DATETIME_FORMAT = new
> >> SimpleDateFormat("MM/dd/yy h:mm a");
> >> private static final SimpleDateFormat DEADLINE_DATETIME_FORMAT = new
> >> SimpleDateFormat("EEEE, MMMM d, yyyy @ h:mm a");
> >>
> >> Then make getters so your ognl reference isn't hideously long:
> >> public Format getShortDatetimeFormat(){
> >>    return SHORT_DATETIME_FORMAT;
> >> }
> >> public Format getDeadlineDatetimeFormat() {
> >>     return DEADLINE_DATETIME_FORMAT;
> >> }
> >>
> >> and then use them in your ognl expression:
> >>
> >> <component id="jobResumeDeadline" type="common:Write">
> >>     <binding name="value" expression="job.resumeDueDate"/>
> >>     <binding name="format" expression="visit.deadlineDatetimeFormat"/>
> >> </component>
> >>
> >> (common:Write) is our own customized version of Insert)
> >>
> >> Patrick Kelly wrote:
> >>
> >>> I have a date originally set as "new
> >>> java.sql.Timestamp(time.getTime()" to my DB.  I retrieve the data in
> >>> string format such as "2005-05-13 12:10:57.0" and I am able to bind
> >>> it with no problem.  However, I need to format the date such as "MMM
> >>> dd, yy, HH:mm:ss" in the binding of a table model.  I would rather do
> >>> the formatting within the .page file than in a .java file.
> >>>
> >>> Any help would be appreciated,
> >>> Thanks - Patrick
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>>
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>
> >
> > --
> > Patrick Kelly
> > E-Learning Consultant
> > Learning Commons, University of Calgary
> > http://commons.ucalgary.ca
> > Phone: 220-2547
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org