code: private Integer highlanderMode(JobDef jd, DbConn cnx)
      {
          if (!jd.isHighlander())
          {
              return null;
          }
  
          try
          {
              Integer existing = cnx.runSelectSingle("ji_select_existing_highlander", Integer.class, jd.getId());
              return existing;
          }
          catch (NoResultException ex)
          {
              // Just continue, this means no existing waiting JI in queue.
          }
  
          // Now we need to actually synchronize through the database to avoid double posting
          // TODO: use a dedicated table, not the JobDef one. Will avoid locking the configuration.
          ResultSet rs = cnx.runSelect(true, "jd_select_by_id", jd.getId());
  
          // Now we have a lock, just retry - some other client may have created a job instance recently.
          try
          {
              Integer existing = cnx.runSelectSingle("ji_select_existing_highlander", Integer.class, jd.getId());
              rs.close();
              cnx.commit(); // Do not keep the lock!
              return existing;
          }
          catch (NoResultException ex)
          {
              // Just continue, this means no existing waiting JI in queue. We keep the lock!
          }
          catch (SQLException e)
          {
              // Who cares.
              jqmlogger.warn("Issue when closing a ResultSet. Transaction or session leak is possible.", e);
          }
  
          jqmlogger.trace("Highlander mode analysis is done: nor existing JO, must create a new one. Lock is hold.");
          return null;
      }
docs: Helper. Current transaction is committed in some cases.