java - JdbcTemplate select for update -


i have spring application reads data database , sends system 'x'. using task executors spin threads, there 5 threads reading database rows @ same time. each thread need make sure unique records selected. achieve using jdbctemplate , "select update"

i have written code in logs able see 2 threads picking same rows. not able figure out root cause of issue. has suggestion

try {     list<map<string, object>> rows = getjdbctemplate().queryforlist(                         select_for_update,                          new object[] {a,b,c,d});       (map<string,object> row : rows) {          header = new header();         a.setmailid(((bigdecimal)row.get("mailid")).intvalue());         a.setversion(((bigdecimal)row.get("version")).intvalue());         // other parameters           getjdbctemplate().update(update_msg_state_version_n_orig_msg_stat,                                   x,                                  a.getversion()+1,                                  y),                                  a.getmailid(),                                  a.getversion());          headers.add(a);     } }  update_msg_state_version_n_orig_msg_stat = update message set msg_stat_cd = ?, version_nbr = ?, orig_msg_stat_cd=?, last_upd_ts=systimestamp message.mail_id = ? , version_nbr = ?   string select_for_update = "select m.mail_id mailid, m.version_nbr version, m.msg_stat_cd state,"                  + "from message m                 + "and m.msg_stat_cd in ('nerwerw')"                 + " , m.create_ts > (sysdate - ?)"                 + " , mod(mail_id,?) = ?"                 + " , rownum <= ?"                 + " order mt.msg_priority update"; 

have had transaction control set up?

if not, transaction happen duration of update statement, , committed automatically (you using oracle believe, base on syntax).

that means, although acquired lock of records, released right-away.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -