Does java have a “LinkedConcurrentHashMap” data structure?

前端 未结 8 1698
猫巷女王i
猫巷女王i 2020-12-01 07:08

I need a data structure that is a LinkedHashMap and is thread safe.

How can I do that ?

8条回答
  •  -上瘾入骨i
    2020-12-01 07:35

    Since the ConcurrentHashMap offers a few important extra methods that are not in the Map interface, simply wrapping a LinkedHashMap with a synchronizedMap won't give you the same functionality, in particular, they won't give you anything like the putIfAbsent(), replace(key, oldValue, newValue) and remove(key, oldValue) methods which make the ConcurrentHashMap so useful.

    Unless there's some apache library that has implemented what you want, you'll probably have to use a LinkedHashMap and provide suitable synchronized{} blocks of your own.

提交回复
热议问题