Hi All,
I have a question regarding synchronizing Array List. I am using an ArayList in a multi threaded environment with Callable interface. I pass an Arraylist object to the Callable method where all the child threads add an entry into the arraylist.
I don't use the arraylist to Iterate anywhere in the Child
thread classes. Should I need to synchronize the Arraylist still even if I do only add into that?
Snippet below, please help
main Class
...
ArrayList<
String> arrList = new ArrayList<String>();
ImplCallable implCallable = new ImplCallable (arrList);
.
.
.
ImplCallable Class
ImplCallable (ArrayList<String> arrList)
{
this.arrList = arrList;
}
call()
{
.
.
.
.
synchronized(arrList )
{
arrList.add(addString);
}
}
Regards
Subash