[英]Spring: Does JdbcTemplate.query() with a RowCallbackHandler make concurrent calls to processRow()?
The Spring docs specify the RowCallbackHandler
argument as an "object that will extract results, one row at a time". Spring文档将
RowCallbackHandler
参数指定为“一次提取结果的对象,一次提取一行”。 I see that processRow()
is called once per row, but can these calls be concurrent? 我看到
processRow()
每行被调用一次,但是这些调用可以并发吗?
I am having my RowCallbackHandler
maintain state, including building a Collection
of processed objects and occasionally submitting that Collection for further processing. 我正在让
RowCallbackHandler
保持状态,包括建立已处理对象的Collection
,并偶尔提交该Collection以进行进一步处理。 I need to know if this Collection
might be modified concurrently, or if I can trust that only one processRow()
is happening at a time. 我需要知道是否可以同时修改此
Collection
,或者我是否可以相信一次仅发生一个processRow()
。
It is really up to you. 真的取决于您。 If you've seen the source code,
RowCallbackHandler
you provide is wrapped in RowCallbackHandlerResultSetExtractor
adapter class and then wrapped again in QueryStatementCallback
(sic!). 如果您已看到源代码,
RowCallbackHandler
您提供的RowCallbackHandler
包装在RowCallbackHandlerResultSetExtractor
适配器类中,然后再次包装在QueryStatementCallback
(原文如此!)。
Never mind, the point is: if you pass the same RowCallbackHandler
instance to two concurrent query()
executions, Spring will use the same object through all this layers. 没关系,关键是:如果将相同的
RowCallbackHandler
实例传递给两个并发的query()
执行,则Spring将在所有这些层中使用相同的对象。 But if you create new instance of RowCallbackHandler
per every query()
execution, you are safe. 但是,如果您在每次执行
query()
都创建RowCallbackHandler
新实例,那是安全的。
If I understand your question, it's 1 row at a time. 如果我理解您的问题,则一次只显示1行。 The example code is from their result set extractor which calls this interface.
示例代码来自其结果集提取器,后者调用此接口。
while (rs.next()) {
this.rch.processRow(rs);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.