1
我剛開始使用Spring Batch,想知道維護在ItemReader中讀取的項目列表的最佳做法是什麼。我看到的例子有這樣的:Spring批處理ItemReader - 維護指針或從列表中刪除項目?
private static List<Resource> items = new LinkedList<Resource>();
private static int index = 0;
private void initialize(){
items.add(new Resource());
}
和
public Model read(){
if(index < items.size())
return new Model(items.get(index++));
return null;
}
什麼是這種方法相較於未使用的指標,簡單地縮短列表的好處是什麼?例如: -
public Model read(){
if(items.size() > 0)
return new Model(items.remove(0));
return null;
}