performance problems in calendar classes in jdk 1.5.0
posted 9 years ago
since upgrading from jdk 1.4.2 to jdk 1.5.0, we are seeing major performance issues in the Calendar class. specifically the before(..), after(...) and equals (...) methods are taking approximately 10 times longer to execute.
i've searched the web and the only other mention of this problem i've found is this link:
My recommendation would be: don't try to compare Calendars directly. Instead, use either getTime() or getTimeInMillis() to convert the Calendar to a nice simple Date or long. The basic problem is that Calendar & GregorianCalendar are hideously overcomplex beasts which try to do too many things, and most of them poorly. Try to use them only for the operations that need a Calendar (e.g. things that depend on knowing how many days are in a month, and which years are leap years). But use Date or a long to represent actual dates and times. Or, look into Joda-time or TimeAndMoney to make your life simpler. [ November 30, 2006: Message edited by: Jim Yingst ]