How to improve performance of SimpleDateFormat wrapped in ThreadLocal?

前端 未结 4 1977
梦如初夏
梦如初夏 2020-12-25 12:54

This is on Java 7 (51) on RHEL with 24 cores We are noticing a rise in average response times of a java SimpleDateFormat wrapped in thread local as we increase the thread po

4条回答
  •  暖寄归人
    2020-12-25 13:26

    Another approach to speed up your formatting is to cache the formatted result. This considers the fact, that there are usually not so many different dates to format. If you split the formatting of date and time, it is even a better candidate for caching.

    The downside of this is, that normal Java cache implementations, like EHCache, are to slow, the cache access just takes longer then the formatting.

    There is another cache implementation around that has access times on par with a HashMap. In this case you get a nice speed up. Here you find my proof of concept tests: https://github.com/headissue/cache2k-benchmark/blob/master/zoo/src/test/java/org/cache2k/benchmark/DateFormattingBenchmark.java

    Maybe this can be a solution within your scenario.

    Disclaimer: I am working on cache2k....

提交回复
热议问题