Making DateFormat Threadsafe. What to use, synchronized or Thread local

前端 未结 6 1553
甜味超标
甜味超标 2020-12-17 22:14

I want to make following code thread safe. What is the best way to achieve it?

private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(         


        
6条回答
  •  再見小時候
    2020-12-17 22:54

    Just create a new copy on each call until it's actually demonstrated to be a performance problem. The overhead of manually managing thread-locals is likely to swamp any advantage you get from caching them.

提交回复
热议问题