I have a 2 threaded process accessing data from a MySQL table. As it is possible with MySQL, I'm getting deadlocked sometimes.
Now, what I've in place is: in case of deadlock,just update all the rows back to their previous state and then restart the process.
But I suspect, something is going wrong as in one case I wanted to update 1300-ish data and after deadlock the count showed 1700-ish.
So, some of the data were processed twice possibly by calling the 2nd instance of the process.
Should I kill all the running threads before restarting the process?
EDIT:
I am using InnoDB with index created on id. The threads are supposed to get whatever rows in limit 500 with Processed flag 'N' is there and process them then update the individual rows to 'Y'.
I also have a process id updated to indicate which thread should act on what rows.
Still I'm getting deadlocked on resultset.updaterow()
Table:
create table Mail(
id integer not null auto_increment primary key,
from_eaddress varchar(50) not null,
to_address varchar(50) not null,
process_flg varchar(1) not null,
process_id varchar(50) default null,
time_stamp datetime default null,
index(id)
) engine=InnoDB;
finally here is my working code: https://github.com/codezero10/MailQueue/tree/master