I have list of object which is read by a single thread but several writer threads can into it.
The reader reads the objects of the list and does some processing.
And the reader thread must wait for a notification from writer threads that the list has been written into.
So each writer thread writes into the list and then notifies the reader . Each time the reader receives a notification it starts its processing and then checks if all the writers are done, if they aren't then it waits again and if all the writers and done then its does a final procesing and exits.
I was able to synchronise the writers but i am not able to synchronize the reader thread and the writer threads.
my code is as follows :-
private List<String> resultList = Collections.synchronizedList(new ArrayList<String>());
private boolean modified = false;
public List<String> getResultList()
public void setResultList(List<String> resultList)
this.resultList = resultList;
public void addElementToResultList(String str)
public synchronized boolean IsModified()
As far as i can see (not to far because you didn't use the CODE tags to make your code readable) your code is a little bit of a mess.
You can start with defining which kind of errors can be thrown and handle the exceptions properly.
So use at least: