struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alberto A. Flores" <aaflo...@gmail.com>
Subject Re: date conversion
Date Wed, 09 Apr 2008 20:16:19 GMT
the synchronized is not needed

Adam Hardy wrote:
> Actually I use it in a static method on a utility class, and call 
> SimpleDateFormat inside a synchronized block.
> 
> Brad A Cupit on 09/04/08 13:51, wrote:
>>>> Consider placing the SimpleDateFormat as a local variable
>> exactly right
>>
>> or, consider using a ThreadLocal
>> or, consider using commons-lang's FastDateFormat
>>
>> http://commons.apache.org/lang/api-release/org/apache/commons/lang/time/
>> FastDateFormat.html
>>
>> Brad Cupit
>> Louisiana State University - UIS
>> e-mail: brad@lsu.edu
>> office: 225.578.4774
>>
>>
>> -----Original Message-----
>> From: Alberto A. Flores [mailto:aaflores@gmail.com] Sent: Wednesday, 
>> April 09, 2008 7:48 AM
>> To: Struts Users Mailing List
>> Subject: Re: date conversion
>>
>> Consider placing the SimpleDateFormat as a local variable (within the 
>> method) to avoid non-thread safe operations (guaranteed by the jvm
>> spec).
>>
>>
>> Brad A Cupit wrote:
>>> the static SimpleDateFormat (assuming this code is in an S2 Action
>> that
>>> is instantiated per request) is not thread safe.
>>>
>>>
>> http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#sy
>>> nchronization
>>>
>>> Brad Cupit
>>> Louisiana State University - UIS
>>>
>>> -----Original Message-----
>>> From: Zoran Avtarovski [mailto:zoran@sparecreative.com] Sent: 
>>> Tuesday, April 08, 2008 7:30 PM
>>> To: Struts Users Mailing List
>>> Subject: Re: date conversion
>>>
>>> We had the same issue and went with writing a new converter (shown
>>> below).
>>> And then created a xwork-conversion.properties file pointing to it.
>>>
>>> Z.
>>>
>>>     private final static SimpleDateFormat DATE_FORMAT = new
>>> SimpleDateFormat("dd/MM/yyyy");     @Override    public Object
>>> convertFromString(Map context, String[] values, Class toType) throws
>>> TypeConversionException {            try {                return
>>> DATE_FORMAT.parse( values[0]);            } catch (ParseException e) {
>>> e.printStackTrace();                throw new
>>> TypeConversionException("xwork.default.invalid.fieldvalue");
>>> }
>>> return null;    }     @Override    public String convertToString(Map
>>> context, Object object) {        Calendar cal =
>> Calendar.getInstance();
>>> cal.setTime((Date) object);                try {             return
>>> DATE_FORMAT.format(object);                } catch (Exception e) {
>>> throw new TypeConversionException("xwork.default.invalid.fieldvalue");
>>> }    }
>>>
>>>> Can you patch a whole class?
>>>>
>>>> What would be useful is parameterizable type converters, to specify
>>> the date
>>>> format in this case. (they're not parameterizable, are they?)
>>>>
>>>> Dave Newton on 08/04/08 22:13, wrote:
>>>>>> --- Adam Hardy <ahardy.struts@cyberspaceroad.com> wrote:
>>>>>>>> One area where S1 actually had the upper hand :(
>>>>>> Submit a patch :)
>>>>>>
>>>>>> Dave
>>>>>>
>>>>>>>> Dave Newton on 08/04/08 18:36, wrote:
>>>>>>>>>> The built-in type converter uses "uses the SHORT
format for the
>>> Locale
>>>>>>>>>> associated with the current request" according to
the type
>>> conversion
>>>>>>>> docs,
>>>>>>>>>> so yes, you'll need to do your own if you're using
a different
>>> input
>>>>>>>> format.
>>>>>>>>>> Looking through the XWork conversion code it's hard
for me to
>>> tell what
>>>>>>>> it's
>>>>>>>>>> *actually* doing, though :/
>>>>>>>>>>
>>>>>>>>>> Dave
>>>>>>>>>>
>>>>>>>>>> --- Brad A Cupit <brad@lsu.edu> wrote:
>>>>>>>>>>
>>>>>>>>>>>> JSTL has the <fmt:formatDate> tag.
If you want to do it in
>>> Java,
>>>>>>>> rather
>>>>>>>>>>>> than your JSP, you can use SimpleDateFormat.
>>>>>>>>>>>>
>>>>>>>>>>>> Be aware that SimpleDataFormat is not thread
safe, so don't
>>> assign it
>>> to
>>>>>>>> a
>>>>>>>>>>>> static field or use it in a singleton. If
you use it as an
>>> instance
>>>>>>>> field
>>>>>>>>>>>> on an Action you'll be safe, since Actions
are created per
>>> request.
>>>>>>>>>>>> If you want a thread safe version of SimpleDateFormat,
>>> Jakarta
>>>>>>>> Commons
>>>>>>>> lang
>>>>>>>>>>>> has FastDateFormat: http://commons.apache.org/lang/
>>>>>>>>>>>>
>>>>>>>>>>>> Brad Cupit
>>>>>>>>>>>> Louisiana State University - UIS
>>>>>>>>>>>> e-mail: brad@lsu.edu
>>>>>>>>>>>> office: 225.578.4774
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> -----Original Message-----
>>>>>>>>>>>> From: Adam Hardy [mailto:ahardy.struts@cyberspaceroad.com]
>>>>>>>>>>>> Sent: Tuesday, April 08, 2008 12:11 PM
>>>>>>>>>>>> To: Struts Users Mailing List
>>>>>>>>>>>> Subject: date conversion
>>>>>>>>>>>>
>>>>>>>>>>>> Hi
>>>>>>>>>>>>
>>>>>>>>>>>> quick question, I can't find any specific
mention of what I
>>> want so I
>>>>>>>>>>>> assume I
>>>>>>>>>>>> have to code my own Converter.
>>>>>>>>>>>>
>>>>>>>>>>>> I need a date in the ISO format YYYY-MM-DD
>>>>>>>>>>>>
>>>>>>>>>>>> There is no converter that I can configure
in the struts
>>> package, is
>>>>>>>> there?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

-- 

Alberto A. Flores
http://www.linkedin.com/in/aflores



Mime
View raw message