JdbcPagingItemReader分页和线程安全

本文通过源码分析JdbcPagingItemReader的分页和线程安全实现。在多线程环境中,JdbcPagingItemReader利用`synchronized`关键字确保线程安全。分页通过`remainingPagesSql`和`firstPageSql`配合`LIMIT`进行,使用`startAfterValues`保存最后读取的row id。当job失败重启时,该分页方式能避免数据变动带来的问题。
摘要由CSDN通过智能技术生成

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的继承关系树:

103423_yFWh_1469576.png

 

当 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());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值