Jun 25th, 2010, 11:43 AM
Cross-thread transactions possible in Spring?
I'm using spring jdbc and programmatic transactions. I have a "dispatcher" that scans an index table and dispatches the work items in the index to many worker threads.
The worker threads are a fixed size pool that always runs. The dispatcher calls an "add" method on the worker thread to add a work item to the workers queue.
The add method starts a transaction and selects for update (to lock the record until processed).
The issue is that the "worker.add" method gets called from the dispatcher and therefore runs in the dispatcher thread the transaction gets created in the dispatcher thread.
Later when the worker runs and pulls things off the queue, the worker thread has no transaction, even though the transaction status is available to the worker as it is with the work item on the queue.
Anyone any idea how I can get one thread to create transactions and another thread to commit them?