|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Synchronized Java method!!! |
« View previous topic :: View next topic » |
Author |
Message
|
vadivel |
Posted: Fri Mar 28, 2008 7:32 am Post subject: Synchronized Java method!!! |
|
|
 Voyager
Joined: 05 Aug 2002 Posts: 79 Location: US
|
Hi,
I'm using WMB 5!!
I have a common subflow that inserts a record into a database table. Before inserting it checks for the key and if it does not exists then inserts the record.
Multiple message flows can use this subflow and if more than one flow invokes this subflow at the sametime with the same key, then one of the insert fails and the other succeeds. As of now I have handled this insert failure by catching the exception and checking if it was primary key violation error.
Is there any other better approach to this?
Can I write this insert logic in Java and call this function from MB? If I make the java function static synchronized, will multiple calls to this method be executed sequentially?
Thanks for your response.
-Vadi |
|
Back to top |
|
 |
JLRowe |
Posted: Fri Mar 28, 2008 8:31 am Post subject: |
|
|
 Yatiri
Joined: 25 May 2002 Posts: 664 Location: South East London
|
What error do you get?
Do you have XA configured?
Currently, the database is doing the synchronization for you, which is what you want really.
Doing it in java is not the answer, as concurrency is difficult to do right, and in any case there is only one lock per execution group (i.e. per JVM) , so accessing the same flows in a different exec group will hit locking issues on the database.
The correct way to do this is:
(a) have your flow retry the transaction by specifying a backout queue, configure the max deliveries on your input queue and have good exception handling
(b) turn on XA for your broker so MQ and the database are coordinated together
(c) tune your SQL for locking levels (e.g. SELECT .... FOR UPDATE can lock a row at the start of a flow) |
|
Back to top |
|
 |
Bill.Matthews |
Posted: Fri Mar 28, 2008 2:38 pm Post subject: Re: Synchronized Java method!!! |
|
|
 Master
Joined: 23 Sep 2003 Posts: 232 Location: IBM (Retired)
|
vadivel wrote: |
I have a common subflow that inserts a record into a database table. Before inserting it checks for the key and if it does not exists then inserts the record.
Multiple message flows can use this subflow and if more than one flow invokes this subflow at the sametime with the same key, then one of the insert fails and the other succeeds. As of now I have handled this insert failure by catching the exception and checking if it was primary key violation error. |
Please consider the following statement: A subflow does NOT exist as a separate entity once a message flow that "includes" this subflow is deployed. Thus, what you have is multiple messages flows that include the same logic, i.e. ESQL statements.
Since, by design, a database key is unique - you will have to handle this with some additional logic, just like you are doing now.
If you were using WMB V6.0 or later, then you could possibly make use of the "atomic" function where a flow could request a lock, do some work, and release the lock.
You also may want to consider your database design - for example, would it be feasible to have the DBM generate a sequential key for each row (so the flow does not have to provide the key)? This can also offer the benefit of a single insert. _________________ Bill Matthews |
|
Back to top |
|
 |
vadivel |
Posted: Fri Apr 11, 2008 7:52 am Post subject: |
|
|
 Voyager
Joined: 05 Aug 2002 Posts: 79 Location: US
|
Thanks for all your answer guys!!!
We decided to use DB to manage the synchronization with little change in our design.
Using Java was a bad idea because every EG has its own JVM, which I was not aware of till now !!!
Thanks again.
-Vadi |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Apr 11, 2008 8:38 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Also, be aware that v5 goes out of support in September. You should be migrating everything to at least version 6 now, so that you can be in production before you lose support. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|