title: Does MySQL has concurrent control on generating auto-increment value?
body: <p>My colleague provides me a code segement that simulates Oracle's sequence:</p>
  
  <pre><code>    // generate ticket
      pstmt = conn.prepareStatement( "insert seq_pkgid values (NULL);" );
      if(pstmt.executeUpdate() &gt; 1) {
          success = 1;
      } else {
          throw new Exception("Generating seq_pkgid sequence failed!");
      }
      pstmt.close();
      pstmt = null;
      // get ticket
      pstmt = conn.prepareStatement( "select last_insert_id() as maxid" );
      rs = pstmt.executeQuery();
      if( rs.next() ) {
          nSeq = rs.getInt( "maxid" );
      }
      rs.close();
      rs = null;
      pstmt.close();
      pstmt = null;
  </code></pre>
  
  <p>But I wonder what if this code segment executed from 2 instances about the same time. Will they get same generated auto-increment value? Does MySQL has concurrent control, e.g. critical section or semaphore, when generating a new auto-increment value?</p>