简体   繁体   中英

what Exception will be thrown when select a MySQL record that is locked with “FOR UPDATE”?

I want to use JDBC to access a MySQL database. What or will an SQLException be thrown if I happen to select a row that is previously locked by a "SELECT ... FOR UPDATE" statement.

Thank you.

I believe, no exception will be thrown, calling Java thread just will be blocked until RDBMS releases locked data. It's normal situation, so need to throw an exception. Think of it as an analog of synchronized block in Java -- JVM doesn't throw an exception when thread tries to enter synchronized block which is occupied by another thread already.

The only situations when exception can be thrown here are:

  1. When connection to RDBMS is lost;
  2. When RDBMS detects deadlock with concurrent transaction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM