I have a situation where there is method that creates an ArrayList and populates the ArrayList with data from a database resultset. The application in question is a multithreaded application. Hence, when two users(threads) access this same method, the arraylist elements are getting out of wack-of course -since ArrayList is not synchronized. When I synchronize the method, it still does not help with the ArrayList even though the arraylist is local to the method. I do not understand that... Since by synchronizing I have a lock on the method, why does a object(the arraylist)local to the method not adhere to the lock?
Example below
public ArrayList getRecords(String className, String structure,
String condition)
{
ArrayList a = new ArrayList();
Object recordData,retval;
rs = getData(structure, condition, "query");
while (rs.next())
{ a.add(recordData);
}
}