code: @Override
      protected void doLock(Connection con, final String lockContext) throws SQLException {
          logger.debug("Trying to acquire db lock for '{}'", lockContext);
          PreparedStatement stmt = con.prepareStatement("select get_lock(?,?)");
          stmt.setString(1, lockContext);
          stmt.setInt(2, ACQUIRE_BLOCKING_WAIT_SEC);
          try {
              final ResultSet rs = stmt.executeQuery();
              while (rs.next()) {
                  final int lockResult = rs.getInt(1);
                  if (lockResult == 1) {
                      // success
                      return;
                  }
  
                  final String errorMsgPrefix = "error acquire lock(" + lockContext + "," + ACQUIRE_BLOCKING_WAIT_SEC + "): ";
                  if (rs.wasNull()) {
                      throw new SQLException(errorMsgPrefix + "unknown");
                  } else if (lockResult == 0) {
                      // timeout
                      throw new SQLException(errorMsgPrefix + "timeout");
                  }
              }
              // something else must be horribly wrong
              throw new SQLException("Please check your version of MySQL, to make sure it supports get_lock() & release_lock()");
          } finally {
              JdbcUtils.closeStatement(stmt);
          }
      }
docs: Note: For MySQL the advisory lock only applies to the current connection, if the connection terminates, it will
  release the lock automatically.
  If you try to lock multiple times on the same lockContext, for the same connection, you need to release multiple
  times, it won't deadlock since version 5.7.5, please consult:
  <a href="http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock">
  http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock</a>