Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jodatime's LocalDateTime is slow when used the first time

Tags:

java

jodatime

I'm currently testing out some webapp technologies in a java project and was wondering why the pages sometimes load fast and sometimes take almost 5s to load.

I finally found out that it is this line

LocalDateTime now = new LocalDateTime();

When it's called the first time, it takes forever to get the current time. When called after that, even somewhere completely different, it's pretty fast however.

I'm currently using

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>1.6.2</version>
    </dependency>

Has anyone had any similar experience? Really stuck here.. I could use LocalDateTime some time early in my application to fasten up subsequent calls - but this seems pretty dull tho.

EDIT

I misuse Spring for that now:

@Service
public class JodaTimeLoader {

  public JodaTimeLoader() {
    LocalDateTime loadMe = new LocalDateTime();
  }

}
like image 509
chzbrgla Avatar asked Jun 08 '11 14:06

chzbrgla


1 Answers

Joda-Time is designed for long running enterprise systems where a one-off up front load time is irrelevant compared to the faster performance during the rest of the application.

like image 85
JodaStephen Avatar answered Nov 02 '22 19:11

JodaStephen