开发者

Java Message Driven Bean(MDB) simultaneous database update issue

开发者 https://www.devze.com 2023-03-20 05:16 出处:网络
I have a java batch process which publishes message processing to MQ. MDB associated with the queue processes the message. Each message will have 10 records. I need to update a database table to keep

I have a java batch process which publishes message processing to MQ. MDB associated with the queue processes the message. Each message will have 10 records. I need to update a database table to keep track of the records processed, successful and failures. There will be only one row in table for each batch run. So the problem is that since multiple instances of MDB are trying to update, we are facing concurrency issues. We tried with row-level locking as well. But the issue still exists.

I am looking for a solution where I can keep track of the counter on the java side and then do a single update after reaching certain threshold. Lets say 500 messages were published. Each message processes 10 records.开发者_如何学运维 The MDB should update this counter after processing all records within this message. The counter will then spawn a thread (if threshold is met) that will update the database.

Please let me know what options are available to me.

App Server - WAS 5.6, DB2 9.1 on Z/OS. Access to DB2 is through SP.

Thanks!


Have you tried doing the update entirely on the DB server? For example:

UPDATE COUNT_TABLE SET COUNTER = COUNTER + 1 WHERE ...

The DB server should be able to manage concurrent update statements like this.


The simplest solution would be to have only a single MDB instance running and your concurrency problem disappears.

This would be a little slower, since you will be doing DB updates of 10 at a time instead of your proposed 500, but unless this is a problem, I would just keep it simple.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号