Some transactions involve 10s of items. Items are retrieved, checked, updated, and replaced sequentially (in serial) using the Java Transaction API. Can we process documents in parallel within a transaction’s context? Let’s say can we retrieve elements in parallel in a transaction or can we insert/replace elements also in parallel?
Yes, absoutely. We provide a reactive API that lets you easily parallelise operations - please see this section of the documentation for details.
Note that currently the API has to be used in a specific way to be thread-safe, as detailed in that documentation link. The next release of the Java transactions library will remove those restrictions, which will make parallel operations even simpler. E.g. you won’t need to perform the first operation in serial anymore, or track failed operations to rollback the transaction. The ETA for the next release is middle of next month.
@graham.pople amazing! We revisited the Java Transaction Library documentation and decided to await your improvement that will remove the restrictions on the thread safety.
Hi @zoltan.zvara
The transactions Java library version 1.2.3 was released yesterday with the discussed improvements. Please see the docs for an updated example of concurrency. (Along with removing the previously required rules, it’s also improved to throttle concurrent operations to a user-set limit.)
Thanks, @graham.pople actually our backend automatically upgraded to version 1.2.3. Then we simply added .par
in Scala to all iterators that process many elements in the transaction, and all of our 1200 tests worked flawlessly.
Ah so you’re using the blocking API? That should work fine too (and gets tested). It’s a lot more painful to do concurrency with blocking APIs in Java, so we recommend Java users use the non-blocking reactive API there, but yes in Scala this seems a valid approach.
Yes, we are using the blocking API in Scala and we make it concurrent in some parts of the application using Scala libraries. We plan to move to non-blocking Scala API eventually but we then have to make sure that the async libraries are compatible when the futures are passed around.
Anyway, great update to the library!