Code example for ThreadFactoryBuilder

0
    // This will create its own client socket channel factory. 
    protected HedwigClientImpl(ClientConfiguration cfg) {
        this(cfg, new NioClientSocketChannelFactory(
                Executors.newCachedThreadPool(new ThreadFactoryBuilder()
                        .setNameFormat("HedwigClient-NIOBoss-%d").build()),
                Executors.newCachedThreadPool(new ThreadFactoryBuilder()
                        .setNameFormat("HedwigClient-NIOWorker-%d").build())));
        ownChannelFactory = true;
    } 
 
    // Constructor that takes in a Configuration object and a ChannelFactory 
    // that has already been instantiated by the caller. 
    protected HedwigClientImpl(ClientConfiguration cfg, ChannelFactory socketFactory) {
        this.cfg = cfg;
        this.socketFactory = socketFactory;
        if (cfg.isSubscriptionChannelSharingEnabled()) {
            channelManager = new MultiplexHChannelManager(cfg, socketFactory);
        } else { 
            channelManager = new SimpleHChannelManager(cfg, socketFactory);
        }