事务提交后,mysql锁仍然存在

时间:2016-05-26 07:46:11

标签: java mysql hibernate transactions locking

提交此事务表后保持锁定状态。如果我第二次执行相同的代码,它会挂起。这是我的Java代码:

Session session = null;
Transaction tx = null;
try{

    session = getSessionNew();
    tx = session.beginTransaction();
    session.createQuery("update cTickFilterMethod set filterMode= :filterMode where id = :id").setInteger("id", id).setInteger("filterMode", filterMode).executeUpdate();
    tx.commit();
}catch (Exception ex){
    ex.printStackTrace();
    Log4Me.getLogger().error("updateActiveFilterMethod exception :" + ex);
    tx.rollback();
}
finally{
    session.close();
}

SHOW ENGINE INNODB状态的结果;

TRANSACTIONS
------------
Trx id counter 804776
Purge done for trx's n:o < 804774 undo n:o < 0 state: running but idle
History list length 1353
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 64, OS thread handle 0x7fbf1682a700, query id 2050 localhost 127.0.0.1 root cleaning up
---TRANSACTION 0, not started
MySQL thread id 63, OS thread handle 0x7fbf167f9700, query id 2051 localhost 127.0.0.1 root cleaning up
---TRANSACTION 0, not started
MySQL thread id 46, OS thread handle 0x7fbf1685b700, query id 2402 localhost 127.0.0.1 root init
SHOW ENGINE INNODB STATUS
---TRANSACTION 0, not started
MySQL thread id 45, OS thread handle 0x7fbf1688c700, query id 1865 localhost 127.0.0.1 root cleaning up
---TRANSACTION 804775, ACTIVE 14 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 65, OS thread handle 0x7fbf16981700, query id 2400 localhost 127.0.0.1 root updating
update tickfiltermethod set filterMode=1 where id=1
------- TRX HAS BEEN WAITING 14 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 1131 page no 3 n bits 72 index `PRIMARY` of table `fdr_trunk`.`tickfiltermethod` trx id 804775 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000000c47a5; asc     G ;;
 2: len 7; hex 220000029806b6; asc "      ;;
 3: len 6; hex 6d656469616e; asc median;;
 4: len 1; hex 01; asc  ;;
 5: len 4; hex 80000002; asc     ;;

------------------
---TRANSACTION 804771, ACTIVE 30 sec
2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 66, OS thread handle 0x7fbf1691f700, query id 2396 localhost 127.0.0.1 root cleaning up
Trx read view will not see trx with id >= 804772, sees < 804769
---TRANSACTION 804769, ACTIVE 30 sec
MySQL thread id 67, OS thread handle 0x7fbf16950700, query id 2310 localhost 127.0.0.1 root cleaning up
Trx read view will not see trx with id >= 804770, sees < 804768

我无法理解为什么会这样。它是关于事务隔离级别的吗?谢谢你的帮助。

0 个答案:

没有答案