docs: protected MCWrapper getSharedConnection(
                                              Object affinity,
                                              Subject subject,
                                              ConnectionRequestInfo cri,
                                              boolean enforceSerialReuse,
                                              String pmiName,
                                              int commitPriority,
                                              int branchCoupling) {
  
          final boolean isTracingEnabled = TraceComponent.isAnyTracingEnabled();
  
          if (isTracingEnabled && tc.isEntryEnabled()) {
              Tr.entry(this, tc, "getSharedConnection");
          }
  
          MCWrapper mcWrapper = null;
          boolean affinityIsEqual = false;
          boolean cmConfigDataIsCompatible = false;
          boolean dumpLTCMessage = true; // We want to only dump one of 86 trace message for every getSharedConnection
  
          /*
           * Dirty read the size of the mcWrapperList. There are no mcWrappers in the
           * list if mcWrapperListSize is zero and it is imposible for a matching
           * mcWrapper and affinity id to be added to this list since this thread has
           * to do the adding.
           */
          if (mcWrapperListSize > 0) {
  
              MCWrapper mcWrapperTemp = null;
              /*
               * We have one or more mcWrapper(s). We need to synchronize.
               */
              synchronized (sharedLockObject) {
                  if (mcWrapperListSize > 0) {
  
                      /*
                       * Look for a matching affinity id and commit priority.
                       */
                      mcWrapperTemp = mcWrapperList[0];
  
                      if (affinity != null && affinity.equals(mcWrapperTemp.getSharedPoolCoordinator())) {
                          affinityIsEqual = true;
  
                          ConnectionManager cm = ((com.ibm.ejs.j2c.MCWrapper) mcWrapperTemp).getCm();
                          ResourceRefInfo resRefInfo = cm.getResourceRefInfo();
                          if (resRefInfo.getCommitPriority() == commitPriority) {
                              int tempBranchCoupling = resRefInfo.getBranchCoupling();
                              if (branchCoupling == tempBranchCoupling) { // Check if they match first for performance
                                  cmConfigDataIsCompatible = true;
                              } else {
                                  cmConfigDataIsCompatible = cm.matchBranchCoupling(branchCoupling, tempBranchCoupling,
                                                                                    ((com.ibm.ejs.j2c.MCWrapper) mcWrapperTemp).get_managedConnectionFactory());
                              }
                          }
  
                      }
  
                  }
  
              } // Lets be really optimistic and release the lock
  
              if (affinityIsEqual && cmConfigDataIsCompatible) {
  
                  // When the new transaction code is drop, we will want to use
                  // the following if test for comparing Coordinators
                  // if (mcWrapperTemp.getSharedPoolCoordinator() == affinity) {
  
                  /*
                   * We have a matching affinity id, now we need a matching user data
                   */
                  boolean subjectMatch = false;
                  Subject mcWrapperSubject = mcWrapperTemp.getSubject();
  
                  if ((subject == null) && (mcWrapperSubject == null)) {
                      subjectMatch = true;
                  } else {
  
                      if ((subject != null) && (mcWrapperSubject != null)) {
  
                          Equals e = new Equals();
                          e.setSubjects(subject, mcWrapperTemp.getSubject());
  
                          if (AccessController.doPrivileged(e)) {
                              subjectMatch = true;
                          }
  
                      }
  
                  }
  
                  ManagedConnection mc = mcWrapperTemp.getManagedConnection();
                  ConnectionRequestInfo mcWrapperCRI = mc instanceof WSManagedConnection ? ((WSManagedConnection) mc).getConnectionRequestInfo() : mcWrapperTemp.getCRI();
                  // The cri can be null, so we need to check for null.
                  boolean criMatch = cri == mcWrapperCRI || cri != null && cri.equals(mcWrapperCRI);
  
                  if (criMatch && subjectMatch) {
  
                      /*
                       * We have a matching affinity id and user data, but we have one more
                       * test. The following if checks the serial reuse rule.
                       */
                      if (enforceSerialReuse && (mcWrapperTemp.getHandleCount() >= 1)) {
  
                          /*
                           * We can not use this connections. We need to look for a shared
                           * connection with the handle count of zero or we need to get a new
                           * shareable connection.
                           */
  
                          if (isTracingEnabled && tc.isDebugEnabled()) {
                              Tr.debug(this, tc, "allocateConnection_Common:  HandleCount = " + mcWrapperTemp.getHandleCount());
                          }
  
                          if (_pm.logSerialReuseMessage) {
                              Tr.info(tc, "ATTEMPT_TO_SHARE_LTC_CONNECTION_J2CA0086", mcWrapperTemp, pmiName);
                              _pm.logSerialReuseMessage = false;
                          }
  
                          if (dumpLTCMessage) {
                              if (isTracingEnabled && tc.isDebugEnabled()) {
                                  dumpLTCMessage = false; // only dump this info once for every getSharedConnection
                                                          // request.
                                  Tr.debug(this, tc, "Attempt to share connection within LTC (J2CA0086)");
                                  Tr.debug(this, tc, "mcWrapper = " + mcWrapperTemp);
                                  Tr.debug(this, tc, "pmiName   = " + pmiName);
                                  Tr.debug(this, tc, "LTC stack information = " + dumpLTCInformation(mcWrapperTemp, pmiName, affinity));
                              }
                          }
  
                      } // end enforceSerialReuse && (mcWrapperTemp.getHandleCount() >= 1)
  
                      else {
  
                          /*
                           * We have a shareable connection to use
                           */
                          if ((isTracingEnabled && tc.isDebugEnabled())) {
                              /*
                               * This is used for tracking shared pool usage data
                               */
                              ++sop_gets;
                          }
  
                          mcWrapper = mcWrapperTemp;
  
                      }
  
                  } // end criMatch && subjectMatch
  
                  else {
  
                      if ((isTracingEnabled && tc.isDebugEnabled())) {
                          /*
                           * This is used for tracking shared pool usage data
                           */
                          ++snop_gets_notfound;
                      }
  
                  } // end else (cri, subj don't both match)
  
              } // end affinityIsEqual && commitPriorityIsEqual
  
              else {
  
                  if ((isTracingEnabled && tc.isDebugEnabled())) {
                      /*
                       * This is used for tracking shared pool usage data
                       */
                      ++snop_gets_notfound;
                  }
  
              }
  
              if (mcWrapper == null) {
                  synchronized (sharedLockObject) {
                      /*
                       * If the mcWrapperListSize > 0, we may have a connection that will
                       * match. We most likely already checked one of the connections, but
                       * we released the shared lock, so we need to check all of them again,
                       * no more perf tricks.
                       */
                      for (int i = 0; i < mcWrapperListSize; ++i) {
  
                          mcWrapperTemp = mcWrapperList[i];
  
                          /*
                           * Look for a matching affinity id and user data.
                           */
  
                          if (affinity != null && affinity.equals(mcWrapperTemp.getSharedPoolCoordinator())) {
  
                              // When the new transaction code is drop, we will want to use
                              // the following if test for comparing Coordinators
                              // if (mcWrapperTemp.getSharedPoolCoordinator() == affinity) {
  
                              /*
                               * We have a matching affinity id, now we need a matching user
                               * data
                               */
                              boolean subjectMatch = false;
                              Subject mcWrapperSubject = mcWrapperTemp.getSubject();
  
                              if ((subject == null) && (mcWrapperSubject == null)) {
                                  subjectMatch = true;
                              } else {
  
                                  if ((subject != null) && (mcWrapperSubject != null)) {
  
                                      Equals e = new Equals();
                                      e.setSubjects(subject, mcWrapperTemp.getSubject());
                                      if ((AccessController.doPrivileged(e)).booleanValue()) {
                                          subjectMatch = true;
                                      }
  
                                  }
  
                              }
  
                              ManagedConnection mc = mcWrapperTemp.getManagedConnection();
                              ConnectionRequestInfo mcWrapperCRI = mc instanceof WSManagedConnection ? ((WSManagedConnection) mc).getConnectionRequestInfo() : mcWrapperTemp.getCRI();
                              // The cri can be null, so we need to check for null.
                              boolean criMatch = cri == mcWrapperCRI || cri != null && cri.equals(mcWrapperCRI);
  
                              if (criMatch && subjectMatch) {
  
                                  /*
                                   * We have a matching affinity id and user data, but we have one
                                   * more test. The following if checks the serial reuse rule.
                                   */
                                  if (enforceSerialReuse && (mcWrapperTemp.getHandleCount() >= 1)) {
                                      /*
                                       * We can not use this connections. We need to look for a
                                       * shared connection with the handle count of zero or we need
                                       * to get a new shareable connection.
                                       */
                                      if (isTracingEnabled && tc.isDebugEnabled()) {
                                          Tr.debug(this, tc, "allocateConnection_Common:  HandleCount = " + mcWrapperTemp.getHandleCount());
                                      }
  
                                      if (_pm.logSerialReuseMessage) {
                                          Tr.info(tc, "ATTEMPT_TO_SHARE_LTC_CONNECTION_J2CA0086", mcWrapperTemp, pmiName);
                                          _pm.logSerialReuseMessage = false;
                                      }
  
                                      if (dumpLTCMessage) {
                                          if (isTracingEnabled && tc.isDebugEnabled()) {
                                              dumpLTCMessage = false; // only dump this info once for every getSharedConnection
                                                                      // request.
                                              Tr.debug(this, tc, "Attempt to share connection within LTC (J2CA0086)");
                                              Tr.debug(this, tc, "mcWrapper = " + mcWrapperTemp);
                                              Tr.debug(this, tc, "pmiName   = " + pmiName);
                                              Tr.debug(this, tc, "LTC stack information = " + dumpLTCInformation(mcWrapperTemp, pmiName, affinity));
                                          }
                                      }
  
                                  } // end enforceSerialReuse && (mcWrapperTemp.getHandleCount() >= 1)
  
                                  else {
  
                                      /*
                                       * Look for a matching commitPriority/branchCoupling.
                                       */
                                      ConnectionManager cm = ((com.ibm.ejs.j2c.MCWrapper) mcWrapperTemp).getCm();
                                      ResourceRefInfo resRefInfo = cm.getResourceRefInfo();
                                      if (resRefInfo.getCommitPriority() == commitPriority) {
                                          int tempBranchCoupling = resRefInfo.getBranchCoupling();
                                          if (branchCoupling == tempBranchCoupling) { // Check if they match first for performance
                                              cmConfigDataIsCompatible = true;
                                          } else {
                                              cmConfigDataIsCompatible = cm.matchBranchCoupling(branchCoupling, tempBranchCoupling,
                                                                                                ((com.ibm.ejs.j2c.MCWrapper) mcWrapperTemp).get_managedConnectionFactory());
                                          }
                                      }
  
                                      if (cmConfigDataIsCompatible) {
  
                                          /*
                                           * We have a shareable connection to use
                                           */
                                          if ((isTracingEnabled && tc.isDebugEnabled())) {
                                              /*
                                               * This is used for tracking shared pool usage data
                                               */
                                              ++snop_gets;
  
                                          }
                                          mcWrapper = mcWrapperTemp;
                                          break;
  
                                      }
  
                                  }
  
                              } // end criMatch && subjectMatch
  
                          } // end mcWrapperTemp.getSharedPoolCoordinator().equals(affinity)
  
                      } // end for loop
  
                  } // end synchronized
  
                  if (mcWrapper == null) {
  
                      if ((isTracingEnabled && tc.isDebugEnabled())) {
                          /*
                           * This is used for tracking shared pool usage data
                           */
                          ++snop_gets_notfound;
                      }
  
                  }
  
              } // end mcWrapper == null
  
          } else {
  
              if ((isTracingEnabled && tc.isDebugEnabled())) {
                  ++sop_gets_notfound;
              }
  
          }
  
          if (isTracingEnabled && tc.isEntryEnabled()) {
              Tr.exit(this, tc, "getSharedConnection", mcWrapper);
          }
  
          return mcWrapper;
  
      }