class AbstractSharedPoolClient extends AbstractClient {
    private static final ThreadPoolExecutor EXECUTOR = new StandardThreadExecutor(1, 300, 20000,
            new DefaultThreadFactory("AbstractPoolClient-initPool-", true));
    private final AtomicInteger idx = new AtomicInteger();
    protected SharedObjectFactory factory;
    protected ArrayList<Channel> channels;
    protected int connections;
    protected volatile boolean poolInit; // Whether the connection pool has been initialized

    public AbstractSharedPoolClient(URL url) {
        super(url);
        connections = url.getIntParameter(URLParamType.minClientConnection.getName(), URLParamType.minClientConnection.getIntValue());
        if (connections <= 0) {
            connections = URLParamType.minClientConnection.getIntValue();
        }
    }

    protected void initPool() {
        factory = createChannelFactory();

        channels = new ArrayList<>(connections);
        for (int i = 0; i < connections; i++) {
            channels.add((Channel) factory.makeObject());
        }
        if (url.getBooleanParameter(URLParamType.lazyInit.getName(), URLParamType.lazyInit.getBooleanValue())) {
            state = ChannelState.ALIVE;
            LoggerUtil.debug("motan client will be lazily initialized. url:" + url.getUri());
            return;
        }
        initConnections(url.getBooleanParameter(URLParamType.asyncInitConnection.getName(), URLParamType.asyncInitConnection.getBooleanValue()));
    }

    protected abstract SharedObjectFactory createChannelFactory();

    protected void initConnections(boolean async) {<FILL_FUNCTION_BODY>}

    private void createConnections() {
        for (Channel channel : channels) {
            try {
                channel.open();
                state = ChannelState.ALIVE;// if any channel is successfully created, the ALIVE status will be set
            } catch (Exception e) {
                LoggerUtil.error("NettyClient init pool create connect Error: url=" + url.getUri(), e);
            }
        }
        poolInit = true;
        if (state == ChannelState.UNINIT) {
            state = ChannelState.UNALIVE; // set state to UNALIVE, so that the heartbeat can be triggered if failed to create connections.
        }
    }

    protected Channel getChannel() {
        if (!poolInit) {
            synchronized (this) {
                if (!poolInit) {
                    createConnections();
                }
            }
        }
        int index = MathUtil.getNonNegativeRange24bit(idx.getAndIncrement());
        Channel channel;

        for (int i = index; i < connections + index; i++) {
            channel = channels.get(i % connections);
            if (!channel.isAvailable()) {
                factory.rebuildObject(channel, i != connections + index - 1);
            }
            if (channel.isAvailable()) {
                return channel;
            }
        }

        String errorMsg = this.getClass().getSimpleName() + " getChannel Error: url=" + url.getUri();
        throw new MotanServiceException(errorMsg);
    }

    protected void closeAllChannels() {
        if (!CollectionUtil.isEmpty(channels)) {
            for (Channel channel : channels) {
                channel.close();
            }
        }
    }
}

        if (async) {
            EXECUTOR.execute(() -> {
                createConnections();
                LoggerUtil.info("async initPool {}. url:{}", state == ChannelState.ALIVE ? "success" : "fail", getUrl().getUri());
            });
        } else {
            createConnections();
        }
    
<methods>public void <init>(com.weibo.api.motan.rpc.URL) ,public java.net.InetSocketAddress getLocalAddress() ,public java.net.InetSocketAddress getRemoteAddress() ,public void heartbeat(com.weibo.api.motan.rpc.Request) ,public void setLocalAddress(java.net.InetSocketAddress) ,public void setRemoteAddress(java.net.InetSocketAddress) <variables>protected com.weibo.api.motan.codec.Codec codec,protected java.net.InetSocketAddress localAddress,protected java.net.InetSocketAddress remoteAddress,protected volatile com.weibo.api.motan.common.ChannelState state,protected com.weibo.api.motan.rpc.URL url