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". I see that processRow()
is called once per row, but can these calls be concurrent?
I am having my RowCallbackHandler
maintain state, including building a Collection
of processed objects and occasionally submitting that Collection for f开发者_JAVA技巧urther processing. 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.
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!).
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. But if you create new instance of RowCallbackHandler
per every query()
execution, you are safe.
If I understand your question, it's 1 row at a time. The example code is from their result set extractor which calls this interface.
while (rs.next()) {
this.rch.processRow(rs);
}
精彩评论