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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> 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: [EMAIL PROTECTED]
> >>> For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >
> > --
> > Patrick Kelly
> > E-Learning Consultant
> > Learning Commons, University of Calgary
> > http://commons.ucalgary.ca
> > Phone: 220-2547
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]