Java - MDB - How to avoid concurrency issue -


we have mdb implemented take user input , processing parallel. have limit check on user data (like number of phone numbers user can have).

the problem i'm facing 2 different threads pickup same user's data , processes. first thread fine , checks limit , adds phone user profile correctly. second thread same. limit check happens before first thread commits transaction, limit check passed. crossed limit.

is there way fix? making 1 user's data picked same thread fine. i'm not sure how that.

please help. in advance.

edit: 1 more thing missed convey. issue happens when running in different nodes.

it depends application server, number of nodes , application, follwing scenarios ok me:

  • weblogic or jboss support unit of order feature:

message unit-of-order weblogic server value-added feature enables stand alone message producer, or group of producers acting one, group messages single unit respect processing order. single unit called unit-of-order , requires messages unit processed sequentially in order created.

  • if update same record first thread acquire lock , second thread wait transaction commit, second thread should check update (optimistic lock) , exit immediatly.

eg.

thread 1: lastupd = now()  thread 1: update mytable set last_update=${lastupd} id=${id} thread 2: lastupd = now() thread 2: update mytable set last_update=${lastupd} id=${id} //remain locked thread 1: lot of work ... thread 1 commit thread 2: lot of work ... thread 2: lastupd2= select last_update mytable id=${id} thread 2: if lastupd2!= lastupd rollback 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -