Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

performance problems in calendar classes in jdk 1.5.0

 
ted chang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

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:

http://forums.java.net/jive/thread.jspa?messageID=37110&tstart=0

has anyone else experienced this problem? is this expected?

thanks,

ted
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing this is because of this new method in java.util.Calendar (as of JDK 5):

Specifically, the clone() method looks like a tedious waste of time in most cases. So why do they do it? It's probably in response to the following bugs:

4340146
4722650
5008227

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic