Jodatime's LocalDateTime is slow when used the first time

こ雲淡風輕ζ 提交于 2019-12-03 22:51:41

The first time you do that, Joda Time loads a number of static resources (e.g., its chronology descriptors) which is the cost that you're seeing. This is a one-off cost; you pay it once per process. Load it early during startup if it really bothers you, perhaps like this:

static {
    // Build the local caches inside Joda Time immediately instead of lazily
    new LocalDateTime();
}

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.

It takes about 77 ms on my system. That is quite long for a class.

Perhaps you just have to call it once on startup to make sure its already loaded.

If you want the current time quickly you can use System.currentTimeMillis(); which takes 0.0018 ms the first time I call it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!