JdbcPagingItemReader分页和线程安全
通过源码来分析其分页和线程安全。
http://my.oschina.net/xinxingegeya/blog/347227
http://my.oschina.net/xinxingegeya/blog/344117
多线程的Step中的每一个commit-interval都是在不同的线程中执行的。在chunk的参与者中reader和writer或许是有状态的,要保证reader和writer在多线程中的线程安全性。那么这里的JdbcPagingItemReader是如何保证线程安全性的。
如下JdbcPagingItemReader的继承关系树:
当 SimpleChunkProvider 调用 itemReader.read() 方法时,如下,
/**
* Surrounds the read call with listener callbacks.
* @return item
* @throws Exception
*/
protected final I doRead() throws Exception {
try {
listener.beforeRead();
I item = itemReader.read();
if(item != null) {
listener.afterRead(item);
}
return item;
}
catch (Exception e) {
logger.debug(e.getMessage() + " : " + e.getClass().getName());