I am new to java multi threading. I would like to write a program in which having 2 threads. One thread adds data to collection structure and other thread is trying to access it. How to implement the same. So do we have to use only concurrenthashmap as collection? Could you please help on this
CodePudding user response:
You are trying to ask a very broad topic through this question. There can be many possibilities depending on the use cases.
But still for a simple put and get scenario, I would recommend using https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingQueue.html
Blocking Queue is a thread safe collection intended to be used for this purpose.