We are just starting to build our JMS architecture and have the following basic setup:
- GLassfish v2.1
- MDB listening on a Topic through a TopicConnectionFactory (all on local server)
Now, the MDB spawns a worker thread when a new message arrives and even though we have in order delivery of messages, we need a synchronization mechanism so that threads check for a certain condition before processing the request concurrently.
Is there a way for these threads to share data? Or are there any other mechanisms (except for database table/row locks) that we can use for synchronization?
Thanks in advance.
To clarify, I am not creating my own threads. As everyone rightly pointed out, the container does that for me. Let me help explain my dilemma with an example.
-Message A arrives at t=0 which 'creates' data id 1
-Message B arrives at t=0.1 which 'updates' data id 1
Now assuming the container spawns 2 workers to process A & B and that it takes much more time to 'create' data than update it, the update would process earlier and have no effect.
To be clearer,
-While processing Message B, I would look for data id 1 at t=1 (not find it and thus have finish without doing anything).
-Data id 1 would be created while processing Message A at t=2.