Code example for ThreadFactoryBuilder

0
  public NettyMapOutputHttpServer(int startingPort) throws IOException {
    this.port = startingPort;
  } 
 
  public synchronized void init(Configuration conf) { 
      ThreadFactory bossFactory = new ThreadFactoryBuilder()
        .setNameFormat("ShuffleHandler Netty Boss #%d")
        .build();
    ThreadFactory workerFactory = new ThreadFactoryBuilder()
        .setNameFormat("ShuffleHandler Netty Worker #%d")
      .build();
 
    int maximumPoolSize = conf.getInt(MAXIMUM_THREAD_POOL_SIZE,
                                      DEFAULT_MAXIMUM_THREAD_POOL_SIZE);
    try { 
      workerThreadPool =
        (ThreadPoolExecutor) Executors.newCachedThreadPool(workerFactory);
      workerThreadPool.setMaximumPoolSize(maximumPoolSize);
    } catch (ClassCastException e) {
      LOG.warn("Netty worker thread pool is not of type ThreadPoolExecutor", e);