ConcurrentHashMap: avoid extra object creation with “putIfAbsent”?

后端 未结 7 2047
北海茫月
北海茫月 2020-12-12 19:10

I am aggregating multiple values for keys in a multi-threaded environment. The keys are not known in advance. I thought I would do something like this:

class         


        
7条回答
  •  春和景丽
    2020-12-12 20:04

    Waste of memory (also GC etc.) that Empty Array list creation problem is handled with Java 1.7.40. Don't worry about creating empty arraylist. Reference : http://javarevisited.blogspot.com.tr/2014/07/java-optimization-empty-arraylist-and-Hashmap-cost-less-memory-jdk-17040-update.html

提交回复
热议问题