-
Apr 5th, 2012, 06:13 PM
#1
Reg...ThreadLocal data when a call is split
Hi,
We use Spring Integration. In one of the flows, the trigger call is split to 3 messages and gets routed. We have some common data gets calculated in service layer and will be passed to this integration layer.
To access that data to be used across all the routed subsystems, I want to use ThreadLocal. But, I'm not sure if the same ThreadLocal data be available when the call is split and executed as 3 messages by different subsystems.
Any clue?
Thanks in adv.
Last edited by ramsbharadwaj; Apr 5th, 2012 at 06:18 PM.
-
Apr 6th, 2012, 06:09 AM
#2
Well, that depends. As long as the split messages are sent to a synchronous channel (DirectChannel or (synch)PubSub) they will all be executed by the same thread and therefore wold be able to share the same ThreadLocal context.
Now, personally I would never recommend to rely on ThreadLocal in these type of scenarios for several reasons. But before I go in details realize one thing. You are building something using Messaging Architecture so your assumptions must be adjusted accordingly.
1. The channel types could change (e.g., you'll decide to go to asynch message exchange model) - your approach won't work
2. Your system might grow and the message processors might have to be distributed across multiple JVM through channel adapters - your approach won't work
3. System crashed while processing the data stored in ThreadLocal. Upon restart the data is unavailable - your approach won't work
And you can probably come up with a few more on your own.
Before i suggest something I am unclear about your statement ". . .calculated in service layer and will be passed to this integration layer...".
How is it passed to the integration layer?
Can it be part of the origina Message (e.g., some header)?
Is this data read-only once calculated or it could still be modified?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules