def checkout
    # Checkout an available connection
    @connection_mutex.synchronize do
      loop do
        conn = if @checked_out.size < @connections.size
                  checkout_existing_connection
                elsif @connections.size < @size
                  checkout_new_connection
                end
        return conn if conn

        @queue.wait(@timeout)

        if(@checked_out.size < @connections.size)
          next
        else
          clear_stale_cached_connections!
          if @size == @checked_out.size
            raise SugarCRM::ConnectionTimeoutError, "could not obtain a sugarcrm connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
          end
        end

      end
    end
  end
def checkout
    # Checkout an available connection
    @connection_mutex.synchronize do
      loop do
        conn = if @checked_out.size < @connections.size
                  checkout_existing_connection
                elsif @connections.size < @size
                  checkout_new_connection
                end
        return conn if conn

        @queue.wait(@timeout)

        if(@checked_out.size < @connections.size)
          next
        else
          clear_stale_cached_connections!
          if @size == @checked_out.size
            raise SugarCRM::ConnectionTimeoutError, "could not obtain a sugarcrm connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
          end
        end

      end
    end
  end
Check-out a sugarcrm connection from the pool, indicating that you want
 to use it. You should call #checkin when you no longer need this.

 This is done by either returning an existing connection, or by creating
 a new connection. If the maximum number of connections for this pool has
 already been reached, but the pool is empty (i.e. they're all being used),
 then this method will wait until a thread has checked in a connection.
 The wait time is bounded however: if no connection can be checked out
 within the timeout specified for this pool, then a ConnectionTimeoutError
 exception will be raised.