RESOLVED - issue BATCH-1389: Thread safety in *PagingReader

Actually you do need to synchronize the whole read.
This commit is contained in:
dsyer
2009-09-04 14:38:48 +00:00
parent 0d94f6f336
commit a4881dfe66
4 changed files with 34 additions and 20 deletions

View File

@@ -94,30 +94,30 @@ public abstract class AbstractPagingItemReader<T> extends AbstractItemCountingIt
@Override
protected T doRead() throws Exception {
if (results == null || current.get() >= pageSize) {
synchronized (lock) {
if (logger.isDebugEnabled()) {
logger.debug("Reading page " + getPage());
}
if (results == null || current.get() >= pageSize) {
synchronized (lock) {
if (results == null || current.get() >= pageSize) {
doReadPage();
page++;
if (current.get() >= pageSize) {
current.set(0);
}
if (logger.isDebugEnabled()) {
logger.debug("Reading page " + getPage());
}
doReadPage();
page++;
if (current.get() >= pageSize) {
current.set(0);
}
}
}
int next = current.getAndIncrement();
if (next < results.size()) {
return results.get(next);
}
else {
return null;
}
int next = current.getAndIncrement();
if (next < results.size()) {
return results.get(next);
}
else {
return null;
}
}