简体   繁体   English

春季:具有RowCallbackHandler的JdbcTemplate.query()是否同时调用processRow()?

[英]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.

相关问题 Spring JDBCTemplate-并发调用 - Spring JDBCTemplate - Concurrent Calls 使用带有参数的 jdbcTemplate.query - Using jdbcTemplate.query with parameters JUnit:mocking jdbcTemplate 的 query() 方法与 RowCallbackHandler - JUnit: mocking jdbcTemplate's query() method with a RowCallbackHandler 使用JdbcTemplate.query(String query,ResultSetExtractor rs)方法的select语句在春季如何工作 - how select statement works in spring using JdbcTemplate.query(String query, ResultSetExtractor rs) method 如何使用参数(Object [] {})模拟jdbcTemplate.query - How to mock jdbcTemplate.query with parameters (Object[]{}) spring boot jdbcTemplate.query throws table not found 自动将表名转换为大写 - spring boot jdbcTemplate.query throws table not found auto converting table name to upper case 如何使用Spring MVC和Spring JdbcTemplate RowCallbackHandler并流式传输结果? - How to use Spring MVC and Spring JdbcTemplate RowCallbackHandler and stream results? jdbcTemplate.query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) 不返回任何结果集 - jdbcTemplate.query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) does not return any resultset RowCallbackHandler与JdbcTemplate的相似度 - Popularity of RowCallbackHandler with JdbcTemplate 简单的jdbcTemplate.query()应该返回一个列表,但不是 - Simple jdbcTemplate.query() is supposed to return a list, but isn't
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM