protected MCWrapper createManagedConnectionWithMCWrapper(
                                                             ManagedConnectionFactory managedConnectionFactory,
                                                             Subject subject,
                                                             ConnectionRequestInfo cri,
                                                             boolean connectionSharing, int hashCode) throws ResourceAllocationException { // This method is called within a synchronize block
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "createManagedConnectionWithMCWrapper");
        }

        ManagedConnection mc = null;
        MCWrapper mcWrapper = null;
        try {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(this, tc, "raClassLoader", raClassLoader);

            JcaServiceUtilities jcasu = new JcaServiceUtilities();
            if (raClassLoader == null) {
                mc = managedConnectionFactory.createManagedConnection(subject, cri);
            } else {
                ClassLoader previousClassLoader = jcasu.beginContextClassLoader(raClassLoader);
                try {
                    mc = managedConnectionFactory.createManagedConnection(subject, cri);
                } finally {
                    jcasu.endContextClassLoader(raClassLoader, previousClassLoader);
                }
            }
            mcWrapper = new com.ibm.ejs.j2c.MCWrapper(pm, gConfigProps);
            mcWrapper.setManagedConnection(mc);

            /*
             * Many threads can hit the following code at the same time. What I a
             * expect to happen is that several threads will hit the synchronized
             * call until the checkForNoPoolingException is set to false.
             */
            if (pm.gConfigProps.checkManagedConnectionInstanceof) {
                /*
                 * Allow only one thread at a time through the following code
                 */
                /*
                 * Double-checked locking works for 32-bit primitive values. I am
                 * using a boolean primitive value.
                 */
                synchronized (pm.gConfigProps.checkManagedConnectionInstanceofLock) {
                    if (pm.gConfigProps.checkManagedConnectionInstanceof) {
                        /*
                         * Call matchManagedConnections
                         */
                        Set<ManagedConnection> s = new HashSet<ManagedConnection>();
                        s.add(mc);
                        try {
                            int poolState = mcWrapper.getPoolState();
                            mcWrapper.setPoolState(50);
                            managedConnectionFactory.matchManagedConnections(s, subject, cri);
                            mcWrapper.setPoolState(poolState);
                        } catch (NotSupportedException e) {
                            /*
                             * If we catch a the NotSupportedException, we need
                             * to turn off connection pooling.
                             */
                            gConfigProps.setConnectionPoolingEnabled(false);
                        }

                        if (mc instanceof DissociatableManagedConnection) {
                            /*
                             * set smart handle supported
                             */
                            pm.gConfigProps.setSmartHandleSupport(true);
                            pm.createParkedConnection = false;
                            pm.gConfigProps.setInstanceOfDissociatableManagedConnection(true);
                        }

                        if (mc instanceof DissociatableManagedConnection) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "Managed connection is an instance of DissociatableManagedConnection");
                            }
                            pm.gConfigProps.setInstanceOfDissociatableManagedConnection(true);
                        }

                        /*
                         * Deferred enlistment
                         */
                        if (mc instanceof LazyEnlistableManagedConnection) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "Managed connection is an instance of LazyEnlistableManagedConnection");
                            }
                            pm.gConfigProps.setDynamicEnlistmentSupported(true);
                        }

                        /*
                         * Create the writer for the managed connection.
                         */
                        pm.writer = new TraceWriter(mc.getClass().getName());
                        pm.traceWriter = (TraceWriter) pm.writer;
                        pm.printWriter = new PrintWriter(pm.writer);

                        /*
                         * We only want to execute this code once
                         * Set this value last in this synchronized block.
                         */
                        pm.gConfigProps.setCheckManagedConnectionInstanceof(false);

                    } // moved brace to include above call to setCheckManagedConnectionInstanceof
                } // end synchronize
            }

            if (tc.isDebugEnabled()) {
                ++freePoolCreateManagedConnection;
            }

            mcWrapper.setFatalErrorValue(fatalErrorNotificationTime + 1);
            mcWrapper.setSubjectCRIHashCode(hashCode);
            mcWrapper.setSubject(subject);
            ((com.ibm.ejs.j2c.MCWrapper) mcWrapper).set_managedConnectionFactory(managedConnectionFactory);
            mcWrapper.setCRI(cri);
            mcWrapper.setSupportsReAuth(gConfigProps.raSupportsReauthentication);
            mcWrapper.setConnectionSynchronizationProvider(gConfigProps.connectionSynchronizationProvider);

            /*
             * Check to see if trace has been turned on for
             * the managed connection.
             */
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(this, tc, "pm = ", pm);
                Tr.debug(this, tc, "traceWriter = ", pm.traceWriter);
            }
            if (pm.traceWriter.isTraceEnabled()) {
                /*
                 * Set the log writer on mc
                 */
                mc.setLogWriter(pm.printWriter);
                mcWrapper.setLogWriterSet(true);
            }

            /*
             * Make sure conneciton pooling is enabled. The reaper is not needed for
             * non poolable resource adapters.
             *
             * First check to see if reaper time is set. We will not be starting the reaper thread unless
             * its set.
             *
             * Next, check to see if its already running.
             */
            if (gConfigProps.isConnectionPoolingEnabled()) {
                if ((pm.reapTime > 0)) {
                    if (pm.alarmThreadCounter.get() == 0) {
                        synchronized (pm.amLockObject) {
                            if (pm.alarmThreadCounter.get() == 0) {
                                /*
                                 * If totalConnectionCount is > minConnections and agedTimeout is not set, start
                                 * the reaper thread.
                                 *
                                 * If agedTimeout is set and totalConnectionCount is > 0 start the reaper
                                 * thread.
                                 */
                                if (pm.agedTimeout < 1) {
                                    if ((pm.totalConnectionCount.get() > pm.minConnections)) {
                                        if (pm.nonDeferredReaperAlarm) {
                                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                                Tr.debug(this, tc, "Creating non-deferrable alarm for reaper");
                                            }
                                            pm.alarmThreadCounter.incrementAndGet();
                                            try {
                                                pm.am = pm.connectorSvc.nonDeferrableSchedXSvcRef.getServiceWithException().schedule(pm, pm.reapTime, TimeUnit.SECONDS);
                                            } catch (Exception e) {
                                                pm.alarmThreadCounter.decrementAndGet();
                                                throw e;
                                            }
                                        } else {
                                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                                Tr.debug(this, tc, "Creating deferrable alarm for reaper");
                                            }
                                            pm.alarmThreadCounter.incrementAndGet();
                                            try {
                                                pm.am = pm.connectorSvc.deferrableSchedXSvcRef.getServiceWithException().schedule(pm, pm.reapTime, TimeUnit.SECONDS);
                                            } catch (Exception e) {
                                                pm.alarmThreadCounter.decrementAndGet();
                                                throw e;
                                            }
                                        }
                                    }
                                } else {
                                    if (pm.totalConnectionCount.get() > 0) {
                                        if (pm.nonDeferredReaperAlarm) {
                                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                                Tr.debug(this, tc, "Creating non-deferrable alarm for reaper");
                                            }
                                            pm.alarmThreadCounter.incrementAndGet();
                                            try {
                                                pm.am = pm.connectorSvc.nonDeferrableSchedXSvcRef.getServiceWithException().schedule(pm, pm.reapTime, TimeUnit.SECONDS);
                                            } catch (Exception e) {
                                                pm.alarmThreadCounter.decrementAndGet();
                                                throw e;
                                            }
                                        } else {
                                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                                Tr.debug(this, tc, "Creating deferrable alarm for reaper");
                                            }
                                            pm.alarmThreadCounter.incrementAndGet();
                                            try {
                                                pm.am = pm.connectorSvc.deferrableSchedXSvcRef.getServiceWithException().schedule(pm, pm.reapTime, TimeUnit.SECONDS);
                                            } catch (Exception e) {
                                                pm.alarmThreadCounter.decrementAndGet();
                                                throw e;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (ResourceException exn) {
            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        exn,
                                                        "com.ibm.ejs.j2c.poolmanager.FreePool.createManagedConnectionWithMCWrapper",
                                                        "199",
                                                        this);
            // call exceptionList method to print stack traces of current and linked exceptions
            Object[] parms = new Object[] { "createManagedConnectionWithMCWrapper", CommonFunction.exceptionList(exn), "ResourceAllocationException", gConfigProps.cfName };
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(this, tc, "POOL_MANAGER_EXCP_CCF2_0002_J2CA0046", parms);
            }
            ResourceAllocationException throwMe = new ResourceAllocationException(exn.getMessage(), exn.getErrorCode());
            throwMe.initCause(exn.getCause());
            pm.activeRequest.decrementAndGet();
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(this, tc, "createManagedConnectionWithMCWrapper", throwMe);
            throw (throwMe);

        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        e,
                                                        "com.ibm.ejs.j2c.poolmanager.FreePool.createManagedConnectionWithMCWrapper",
                                                        "545",
                                                        this);
            // call exceptionList method to print stack traces of current and linked exceptions
            Object[] parms = new Object[] { "createManagedConnectionWithMCWrapper", CommonFunction.exceptionList(e), "ResourceAllocationException", gConfigProps.cfName };
            Tr.error(tc, "POOL_MANAGER_EXCP_CCF2_0002_J2CA0046", parms);
            ResourceAllocationException throwMe = new ResourceAllocationException(e.getMessage());
            throwMe.initCause(e);
            pm.activeRequest.decrementAndGet();
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(this, tc, "createManagedConnectionWithMCWrapper", throwMe);
            throw (throwMe);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "createManagedConnectionWithMCWrapper", mcWrapper);
        }
        return mcWrapper;

    }
protected MCWrapper createManagedConnectionWithMCWrapper ( ManagedConnectionFactory managedConnectionFactory , Subject subject , ConnectionRequestInfo cri , boolean connectionSharing , int hashCode ) throws ResourceAllocationException { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { Tr . entry ( this , tc , "createManagedConnectionWithMCWrapper" ) ; } ManagedConnection mc = null ; MCWrapper mcWrapper = null ; try { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( this , tc , "raClassLoader" , raClassLoader ) ; JcaServiceUtilities jcasu = new JcaServiceUtilities ( ) ; if ( raClassLoader == null ) { mc = managedConnectionFactory . createManagedConnection ( subject , cri ) ; } else { ClassLoader previousClassLoader = jcasu . beginContextClassLoader ( raClassLoader ) ; try { mc = managedConnectionFactory . createManagedConnection ( subject , cri ) ; } finally { jcasu . endContextClassLoader ( raClassLoader , previousClassLoader ) ; } } mcWrapper = new com . ibm . ejs . j2c . MCWrapper ( pm , gConfigProps ) ; mcWrapper . setManagedConnection ( mc ) ; if ( pm . gConfigProps . checkManagedConnectionInstanceof ) { synchronized ( pm . gConfigProps . checkManagedConnectionInstanceofLock ) { if ( pm . gConfigProps . checkManagedConnectionInstanceof ) { Set < ManagedConnection > s = new HashSet < ManagedConnection > ( ) ; s . add ( mc ) ; try { int poolState = mcWrapper . getPoolState ( ) ; mcWrapper . setPoolState ( 50 ) ; managedConnectionFactory . matchManagedConnections ( s , subject , cri ) ; mcWrapper . setPoolState ( poolState ) ; } catch ( NotSupportedException e ) { gConfigProps . setConnectionPoolingEnabled ( false ) ; } if ( mc instanceof DissociatableManagedConnection ) { pm . gConfigProps . setSmartHandleSupport ( true ) ; pm . createParkedConnection = false ; pm . gConfigProps . setInstanceOfDissociatableManagedConnection ( true ) ; } if ( mc instanceof DissociatableManagedConnection ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Managed connection is an instance of DissociatableManagedConnection" ) ; } pm . gConfigProps . setInstanceOfDissociatableManagedConnection ( true ) ; } if ( mc instanceof LazyEnlistableManagedConnection ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Managed connection is an instance of LazyEnlistableManagedConnection" ) ; } pm . gConfigProps . setDynamicEnlistmentSupported ( true ) ; } pm . writer = new TraceWriter ( mc . getClass ( ) . getName ( ) ) ; pm . traceWriter = ( TraceWriter ) pm . writer ; pm . printWriter = new PrintWriter ( pm . writer ) ; pm . gConfigProps . setCheckManagedConnectionInstanceof ( false ) ; } } } if ( tc . isDebugEnabled ( ) ) { ++ freePoolCreateManagedConnection ; } mcWrapper . setFatalErrorValue ( fatalErrorNotificationTime + 1 ) ; mcWrapper . setSubjectCRIHashCode ( hashCode ) ; mcWrapper . setSubject ( subject ) ; ( ( com . ibm . ejs . j2c . MCWrapper ) mcWrapper ) . set_managedConnectionFactory ( managedConnectionFactory ) ; mcWrapper . setCRI ( cri ) ; mcWrapper . setSupportsReAuth ( gConfigProps . raSupportsReauthentication ) ; mcWrapper . setConnectionSynchronizationProvider ( gConfigProps . connectionSynchronizationProvider ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "pm = " , pm ) ; Tr . debug ( this , tc , "traceWriter = " , pm . traceWriter ) ; } if ( pm . traceWriter . isTraceEnabled ( ) ) { mc . setLogWriter ( pm . printWriter ) ; mcWrapper . setLogWriterSet ( true ) ; } if ( gConfigProps . isConnectionPoolingEnabled ( ) ) { if ( ( pm . reapTime > 0 ) ) { if ( pm . alarmThreadCounter . get ( ) == 0 ) { synchronized ( pm . amLockObject ) { if ( pm . alarmThreadCounter . get ( ) == 0 ) { if ( pm . agedTimeout < 1 ) { if ( ( pm . totalConnectionCount . get ( ) > pm . minConnections ) ) { if ( pm . nonDeferredReaperAlarm ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Creating non-deferrable alarm for reaper" ) ; } pm . alarmThreadCounter . incrementAndGet ( ) ; try { pm . am = pm . connectorSvc . nonDeferrableSchedXSvcRef . getServiceWithException ( ) . schedule ( pm , pm . reapTime , TimeUnit . SECONDS ) ; } catch ( Exception e ) { pm . alarmThreadCounter . decrementAndGet ( ) ; throw e ; } } else { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Creating deferrable alarm for reaper" ) ; } pm . alarmThreadCounter . incrementAndGet ( ) ; try { pm . am = pm . connectorSvc . deferrableSchedXSvcRef . getServiceWithException ( ) . schedule ( pm , pm . reapTime , TimeUnit . SECONDS ) ; } catch ( Exception e ) { pm . alarmThreadCounter . decrementAndGet ( ) ; throw e ; } } } } else { if ( pm . totalConnectionCount . get ( ) > 0 ) { if ( pm . nonDeferredReaperAlarm ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Creating non-deferrable alarm for reaper" ) ; } pm . alarmThreadCounter . incrementAndGet ( ) ; try { pm . am = pm . connectorSvc . nonDeferrableSchedXSvcRef . getServiceWithException ( ) . schedule ( pm , pm . reapTime , TimeUnit . SECONDS ) ; } catch ( Exception e ) { pm . alarmThreadCounter . decrementAndGet ( ) ; throw e ; } } else { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Creating deferrable alarm for reaper" ) ; } pm . alarmThreadCounter . incrementAndGet ( ) ; try { pm . am = pm . connectorSvc . deferrableSchedXSvcRef . getServiceWithException ( ) . schedule ( pm , pm . reapTime , TimeUnit . SECONDS ) ; } catch ( Exception e ) { pm . alarmThreadCounter . decrementAndGet ( ) ; throw e ; } } } } } } } } } } catch ( ResourceException exn ) { com . ibm . ws . ffdc . FFDCFilter . processException ( exn , "com.ibm.ejs.j2c.poolmanager.FreePool.createManagedConnectionWithMCWrapper" , "199" , this ) ; Object [ ] parms = new Object [ ] { "createManagedConnectionWithMCWrapper" , CommonFunction . exceptionList ( exn ) , "ResourceAllocationException" , gConfigProps . cfName } ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "POOL_MANAGER_EXCP_CCF2_0002_J2CA0046" , parms ) ; } ResourceAllocationException throwMe = new ResourceAllocationException ( exn . getMessage ( ) , exn . getErrorCode ( ) ) ; throwMe . initCause ( exn . getCause ( ) ) ; pm . activeRequest . decrementAndGet ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) Tr . exit ( this , tc , "createManagedConnectionWithMCWrapper" , throwMe ) ; throw ( throwMe ) ; } catch ( Exception e ) { com . ibm . ws . ffdc . FFDCFilter . processException ( e , "com.ibm.ejs.j2c.poolmanager.FreePool.createManagedConnectionWithMCWrapper" , "545" , this ) ; Object [ ] parms = new Object [ ] { "createManagedConnectionWithMCWrapper" , CommonFunction . exceptionList ( e ) , "ResourceAllocationException" , gConfigProps . cfName } ; Tr . error ( tc , "POOL_MANAGER_EXCP_CCF2_0002_J2CA0046" , parms ) ; ResourceAllocationException throwMe = new ResourceAllocationException ( e . getMessage ( ) ) ; throwMe . initCause ( e ) ; pm . activeRequest . decrementAndGet ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) Tr . exit ( this , tc , "createManagedConnectionWithMCWrapper" , throwMe ) ; throw ( throwMe ) ; } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { Tr . exit ( this , tc , "createManagedConnectionWithMCWrapper" , mcWrapper ) ; } return mcWrapper ; }
Return a mcWrapper. Create one if the
maximum connection limit has not been reached. If the maximum had been reached,
queue the request.

@throws ResourceAllocationException