protected void configureThreadPool(
      final ServiceLocator habitat,
      final NetworkListener networkListener,
      final ThreadPool threadPool) {

    final String classname = threadPool.getClassname();
    if (classname != null && !ThreadPool.DEFAULT_THREAD_POOL_CLASS_NAME.equals(classname)) {

      // Use custom thread pool
      try {
        final ExecutorService customThreadPool =
            Utils.newInstance(habitat, ExecutorService.class, classname, classname);

        if (customThreadPool != null) {
          if (!configureElement(habitat, networkListener, threadPool, customThreadPool)) {
            LOGGER.log(
                Level.INFO,
                "The ThreadPool configuration bean can not be "
                    + "passed to the custom thread-pool: {0}"
                    + " instance, because it's not {1}.",
                new Object[] {classname, ConfigAwareElement.class.getName()});
          }

          workerExecutorService = customThreadPool;
          transport.setWorkerThreadPool(customThreadPool);
          return;
        }

        LOGGER.log(Level.WARNING, "Can not initalize custom thread pool: {0}", classname);

      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Can not initalize custom thread pool: " + classname, t);
      }
    }

    try {
      // Use standard Grizzly thread pool
      workerExecutorService =
          GrizzlyExecutorService.createInstance(
              configureThreadPoolConfig(networkListener, threadPool));
      transport.setWorkerThreadPool(workerExecutorService);
    } catch (NumberFormatException ex) {
      LOGGER.log(Level.WARNING, "Invalid thread-pool attribute", ex);
    }
  }