1

I would like to have possibilities like ConcurrentMap gives me so:

  • thread-safe
  • performance-efficient
  • Id indicator as a key
  • object in a value
  • random-access to specific elements

And additionally, I would like to keep the order in which the messages are stored. Do anyone know which structure could fulfil the requirements or should I write my own implementation? Maybe anyone knows any useful library for such a problem?

I thought about ConcurrentNavigableMap as it is an extension of SortedMap. However, as I understand it well it will sort the elements in a specific order, not keep the order of inserting. I would also avoid having any BlockingQueue or BlockingDeque as I would like to have random access to specific elements.

I really appreciate your help.

Alex R
  • 175
  • 1
  • 12
  • 4
    Seems duplicate of https://stackoverflow.com/questions/1391918/does-java-have-a-linkedconcurrenthashmap-data-structure – Jim Sep 01 '20 at 10:01
  • 1
    When your requirements are this specific, consider it likely that you're going to have to concede that it doesn't exist and write it yourself. – Michael Sep 01 '20 at 10:05
  • No, it's not @Jim - in the topic which you propose solutions doesn't have efficiency - Collections.synchronizedMap is slow and doesn't keep the order of insertion. – Alex R Sep 01 '20 at 10:05
  • 1
    @RydA: the order of insertion is kept due to using a `LinkedHashMap` wrapped. As for the efficiency I would say if you haven't test it you can't know, and that it might be much faster than your custom solution. Check https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html – Jim Sep 01 '20 at 10:08
  • Yeah, I was afraid this will be the problem @Michael. But I will leave it here as maybe someone know any interesting library which solves the problem. Would be really nice to have it – Alex R Sep 01 '20 at 10:09

0 Answers0