Object corruption when retrieving object from List
Hi,
We have a batch program. There are muliple threads running which read data from database and then processes the data.
In each thread. there is a call to fetch data from a table, create objects and populate a list and return it.
This list is then given to another method which processes each item from the list
This is a simplified version of what the code looks like.
public class Manager{
public void run(){
Reader r = new Reader();
Processor processor = new Processor();
List list = reader.getItems();
processor.processItem(list);
}
}
public class Reader{
public List getItems(){
List list = new ArrayList();
// Resultset rs = execute a query and get
// a resultset object
while(rs.next()){
Item item = new Item();
// set information from rs and set
//into item
list.add(item);
}
return list;
}
}
public class Processor {
public processItem(List list){
Item item = null;
while (!list.isEmpty()){
item = (Item)list.remove(0);
}
}
}
In the processItem method of Processor class, when I retrieve item from the List
it should return me an object of type Item. But very rarely what happens is that
the object I return is not of type Item, but null or a junk class like [C@1309b55.
Once this happens, i get a class cast exception when i am trying to cast this to
Item class.
Can anyone please tell me if you have encountered such a scenario before?
The process is running in a 2 processor environment.
It's mulithreaded, but method calls are done from within a thread.
The ArrayList is not shared across multiple threads. It's life starts
and ends within the run method of the thread.

