Problems in Details
Will it cause any issue when using data structure e.g ArrayBlockingQueue<ArrayList<MyClass>>
with multiple threads?
Background
In a high level, i am trying to achieve that I have one producer which will produce a giant list. In order to speed up the processing. I decide to use multiple consumers(threads) consuming the giant list produced by the producer.
My Proposal Solution
I will be converting the giant list to multiple relatively smaller list and in order to ensure its thread safe, I will enqueue these smaller lists to a concurrent data structure. So in multi-threads scenario, each thread just poll the concurrent queue to get one list and work on it.
Problem Statement
In multi-threads scenario, I understand we have to use the concurrent data structure to avoid thread interference and build happen-before relation.
But will it be safe that using non-thread-safe data structure as element of thread-safe data structure?
Will it cause any issue when using data structure e.g
ArrayBlockingQueue<ArrayList<MyClass>>
with multiple threads?- Will it be any impact to the performance?
>`, then i can reduce the interaction of between different threads and the shared variable.
– Huazhe Yin Jun 03 '19 at 16:45