You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by jill han <jh...@bynum.com> on 2007/06/14 17:37:07 UTC

Calendar vs GregorianCalendar

I know it is not related to turbine question, but I still count on your
help.
Here is a code snippet 
****************
private List getResponsesToProcess() throws TorqueException
{
// get the current date and set the time to midnight
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MILLISECOND, 0);

// select all responses that are email
Criteria crit = new Criteria();
crit.addJoin(XXXPeer.DELIVERY_METHOD_ID, XXXXPeer.OBJECT_ID);
....
crit.add(ResponsePeer.DELIVERY_DATE, today.getTime(),
Criteria.LESS_EQUAL);

List results = ResponsePeer.doSelect(crit);

crit = new Criteria();
crit.addJoin(XXXPeer.DELIVERY_METHOD_ID, XXXXPeer.OBJECT_ID);
...
results.addAll(XXXPeer.doSelect(crit));

return results;
}
*****************
However someone suggested to 
"Synchronize the part of the code that uses the Calendar objects or
create new objects of GregorianCalendar and avoid using
Calender.getInstance unless that part of the code is synchronized"
I didn't see why it needs synchronization and the applicable difference
of GregorianCalendar and Calender object.

I really appreciate if someone could give some insights into it 


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


Re: Calendar vs GregorianCalendar

Posted by Will Glass-Husain <wg...@gmail.com>.
A bit off-topic, but there's a great rant on the various Date types (with
some history) here:
http://jroller.com/page/cpurdy?entry=the_seven_habits_of_highly

I like this part:

"As far as java.util.Calendar goes, I'm sure it has a purpose, but since
we've been on the Gregorian now for several friggin' centuries (and with no
sign of imminent change), I think we'd be safe having Calendar be one of
those classes that is neither seen nor heard except in the 0.000001% chance
that you actually need to do something with the scrolls of dead monks."

WILL


On 6/14/07, Siegfried Goeschl <si...@it20one.at> wrote:
>
> Hi Jill,
>
> +) Calendar is an abstract class and usually the only concrete
> implementation is an GregorianCalendar until Java 6 (see
>
> http://weblogs.java.net/blog/joconner/archive/2005/09/overview_of_mus_1.html
> ).
> There you also have a Japanese calendar
>
> +) I'm not aware of any thread-safety issues apart from
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178997
>
> Cheers,
>
> Siegfried Goeschl
>
>
>
> jill han wrote:
> > I know it is not related to turbine question, but I still count on your
> > help.
> > Here is a code snippet
> > ****************
> > private List getResponsesToProcess() throws TorqueException
> > {
> > // get the current date and set the time to midnight
> > Calendar today = Calendar.getInstance();
> > today.set(Calendar.HOUR_OF_DAY, 0);
> > today.set(Calendar.MINUTE, 0);
> > today.set(Calendar.HOUR_OF_DAY, 0);
> > today.set(Calendar.MILLISECOND, 0);
> >
> > // select all responses that are email
> > Criteria crit = new Criteria();
> > crit.addJoin(XXXPeer.DELIVERY_METHOD_ID, XXXXPeer.OBJECT_ID);
> > ....
> > crit.add(ResponsePeer.DELIVERY_DATE, today.getTime(),
> > Criteria.LESS_EQUAL);
> >
> > List results = ResponsePeer.doSelect(crit);
> >
> > crit = new Criteria();
> > crit.addJoin(XXXPeer.DELIVERY_METHOD_ID, XXXXPeer.OBJECT_ID);
> > ...
> > results.addAll(XXXPeer.doSelect(crit));
> >
> > return results;
> > }
> > *****************
> > However someone suggested to
> > "Synchronize the part of the code that uses the Calendar objects or
> > create new objects of GregorianCalendar and avoid using
> > Calender.getInstance unless that part of the code is synchronized"
> > I didn't see why it needs synchronization and the applicable difference
> > of GregorianCalendar and Calender object.
> >
> > I really appreciate if someone could give some insights into it
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
> > For additional commands, e-mail: user-help@turbine.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
> For additional commands, e-mail: user-help@turbine.apache.org
>
>


-- 
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

Re: Calendar vs GregorianCalendar

Posted by Siegfried Goeschl <si...@it20one.at>.
Hi Jill,

+) Calendar is an abstract class and usually the only concrete 
implementation is an GregorianCalendar until Java 6 (see 
http://weblogs.java.net/blog/joconner/archive/2005/09/overview_of_mus_1.html). 
There you also have a Japanese calendar

+) I'm not aware of any thread-safety issues apart from 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178997

Cheers,

Siegfried Goeschl



jill han wrote:
> I know it is not related to turbine question, but I still count on your
> help.
> Here is a code snippet 
> ****************
> private List getResponsesToProcess() throws TorqueException
> {
> // get the current date and set the time to midnight
> Calendar today = Calendar.getInstance();
> today.set(Calendar.HOUR_OF_DAY, 0);
> today.set(Calendar.MINUTE, 0);
> today.set(Calendar.HOUR_OF_DAY, 0);
> today.set(Calendar.MILLISECOND, 0);
> 
> // select all responses that are email
> Criteria crit = new Criteria();
> crit.addJoin(XXXPeer.DELIVERY_METHOD_ID, XXXXPeer.OBJECT_ID);
> ....
> crit.add(ResponsePeer.DELIVERY_DATE, today.getTime(),
> Criteria.LESS_EQUAL);
> 
> List results = ResponsePeer.doSelect(crit);
> 
> crit = new Criteria();
> crit.addJoin(XXXPeer.DELIVERY_METHOD_ID, XXXXPeer.OBJECT_ID);
> ...
> results.addAll(XXXPeer.doSelect(crit));
> 
> return results;
> }
> *****************
> However someone suggested to 
> "Synchronize the part of the code that uses the Calendar objects or
> create new objects of GregorianCalendar and avoid using
> Calender.getInstance unless that part of the code is synchronized"
> I didn't see why it needs synchronization and the applicable difference
> of GregorianCalendar and Calender object.
> 
> I really appreciate if someone could give some insights into it 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
> For additional commands, e-mail: user-help@turbine.apache.org
> 
> 
> 

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