0

I want to read and write into a Java list at the same time.

for example, I want to fill my list from a data source (ex: producers), and read the data using other programs (Apache storm with spot).

to give you a clear idea there is a broker who sends data to Apache storm: Broker -> My API Broker ->spout -> Bolt so my api receive data and try to fill my list and the spout read data, and remove it from the list.

but if tried to do this, I will receive the exception : ConcurrentModificationException

h.zak
  • 1,407
  • 5
  • 21
  • 40
  • 4
    That is to be expected. Also, do you retrieve elements at random positions or only from the beginning/end? If the latter, consider using a `BlockingQueue`: this class is dedicated to such uses – fge Apr 26 '16 at 14:24
  • I didn't start coding, but, I try to design how I will work. For your question about retrieving, I will work using first in first out – h.zak Apr 26 '16 at 14:28
  • 2
    Then a `BlockingQueue` it is. Try a [`LinkedBlockingQueue`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html) for instance. – fge Apr 26 '16 at 14:32
  • Thank you, last question, do you know what is the difference between BlockingQueue and LinkedBlockingQueue, and which one is more efficient (my messages are just byte[] data or string) – h.zak Apr 26 '16 at 14:40
  • 2
    [`BlockingQueue`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/BlockingQueue.html) is an *interface*. [`LinkedBlockingQueue`](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html) is a *class* implementing it. – Andreas Apr 26 '16 at 14:48
  • Possible duplicate of [Is there a concurrent List in Java's JDK?](http://stackoverflow.com/questions/6916385/is-there-a-concurrent-list-in-javas-jdk) – Matthias J. Sax Apr 29 '16 at 14:40

0 Answers0