Reputation: 1193
I'm using Java and MySql as a database.
I'm running multiple instances of application. I'm selecting one record from the database and at the same time after fetching, I'm updating its status as "in process" so that no other instances can access that record.
But what happens is the instances is running so fast that, when one instance is accessing one record, the other instance is also accessing the same record before the update is done to "In Process" by first instance. What should I do so that the update also takes place before the other instance can access it? I have used conn.setTransactionIsolation(conn.TRANSACTION_READ_COMMITTED)
in my code, but this also not helping.
Thanks in advance.
Upvotes: 3
Views: 149
Reputation: 31928
You need a select for update
type of statement.
http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html
Upvotes: 2
Reputation: 1466
Well I think the solution of your problem is synchronization block.There are two ways to do it .Either write synchronization block or put that update database code into one method which is synchronized. So that if one thread is making the changes then no other thread will access it. For more reference click here
Upvotes: 0