@Override
    public final void close() {
        lock.readLock().lock();
        try {
            if (!initialized) {
                return;
            }
        } finally {
            lock.readLock().unlock();
        }

        lock.writeLock().lock();
        try {
            server = null;

            if (connection != null) {
                closeConnection(connection, false);
                connection = null;
            }

            // avoid shutting down shared thread pool
            if (executor != null && config.getMaxThreadsPerClient() > 0 && !executor.isTerminated()) {
                executor.shutdown();
            }
            executor = null;
        } catch (Exception e) {
            log.warn("Exception occurred when closing client", e);
        } finally {
            initialized = false;
            try {
                if (connection != null) {
                    closeConnection(connection, true);
                }

                if (executor != null && config.getMaxThreadsPerClient() > 0) {
                    executor.shutdownNow();
                }
            } finally {
                executor = null;
                connection = null;
                lock.writeLock().unlock();
            }
        }
    }
Gets a connection according to the given request.

@param request non-null request
@return non-null connection
@throws CompletionException when error occured
clickhouse-client/src/main/java/com/clickhouse/client/AbstractClient.java