Im facing one problem in streaming data capture for reading the broadcast data during multithreading, pls help or suggest,

Actually there is one class which is reading data from one of the udp socket. Another class accepts the tcp connection from every client request, creates a thread for every client and request the same udp class for data. The thing is working with 1st thread which gets created. But when i request with another client from another pc/ip the packets get losted to the 2nd client/thread

I have made a workaround by creating a list where im storing the Threads outputstream object
and looping it to send the data to all the client. But this is just temporary as it ll delay the packets if clients/connections gets increased.

You still have } catch(Exception e3) {} and you still haven't clarified your question. I don't understand this sentence: "Another class accepts the tcp connection from every client request, creates a thread for every client and request the same udp class for data."
–
EJPJun 25 '12 at 7:44

1 Answer
1

For example, what will happen if two threads call multiServer.writers.add(out); concurrently?

From the ArrayList Javadocs

Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or [...])

Another problem is two calling udp_data = en.getDataFeed(cliString); concurrently. The second thread might overwrite the result of the first. You'll loose data!

What happens if one thread calls for (int i=0; i<multiServer.writers.size();i++) while another thread is busy doing multiServer.writers.add(out);? The size may have increased, before out has actually been added to the list!

There might be more problems, not sure I don't fully understand your code. The question you must ask yourself is, can another thread read and/or write the same data or object? Yes? Then you'll need proper synchronization.

Thanks for ur reply my problem is like the data which is read on udp port by every thread should be consistent and concurrent across every thread.i understand that there will be a data lost if same variable or method is being overwritted or called thats y i need a solution how to call a method within the thread which ll unqiuely identify every thread and data will be same across all threads
–
praveen2609Jun 25 '12 at 8:43

Im new to this blog, is there any ways to chat with you i may explain u my problem exactly
–
praveen2609Jun 25 '12 at 9:06

As per my understanding what u said is like , i need to make synchronization for the writers.add and to serverallwriters, but in that case every thread will call the same method and will server the data multiple times doesn't it have lost of data packets from udp
–
praveen2609Jun 25 '12 at 9:14