return an instance to the thread factory used to create new executor services
556799
private static ThreadFactory getThreadFactory(final String nameFormat) {
        final ThreadFactory defaultThreadFactory = Executors.privilegedThreadFactory();
        return new ThreadFactory() {
            final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null;

            @Override
            public Thread newThread(Runnable runnable) {
                Thread thread = defaultThreadFactory.newThread(runnable);
                if (nameFormat != null) {
                    thread.setName(String.format(nameFormat, count.getAndIncrement()));
                }
                return thread;
            }
        };
    }
422789
public static ExecutorService createBackgroundExecutor() {
		final ExecutorService executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory(DEFAULT_BACKGROUND_EXECUTOR_NAME));
		BACKGROUND_EXECUTORS.add(executor);
		return executor;
	}
891326
public static ExecutorService newMaxQueueThreadPool(int numWorkerThreads,
            long waitingMillis, int maxQueue) {
        return new ThreadPoolExecutor(numWorkerThreads, numWorkerThreads,
                0L, TimeUnit.MILLISECONDS,
                waitingMillis > 0 ? getWaitingLimitedBlockingQueue(
                        waitingMillis, maxQueue) : getLimitedBlockingQueue(
                        maxQueue));
    }
1261366
private FutureRequestExecutionService buildRequestExecutorService(final CloseableHttpClient httpClient) {
        if (this.executorService == null) {
            this.executorService = new ThreadPoolExecutor(this.threadsNumber, this.threadsNumber, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(this.queueSize));
        }
        return new FutureRequestExecutionService(httpClient, this.executorService);
    }
496505
static synchronized ExecutorService getExecutorService() {
        if (executorService == null) {
            executorService = Executors.newCachedThreadPool(new NamingThreadFactory(new DaemonThreadFactory(), "org.jenkinsci.plugins.pipeline.maven.fix.jenkins49337.GeneralNonBlockingStepExecution"));
        }
        return executorService;
    }
1020566
@Override
    protected Thread createThread(final Runnable runnable, final String name) {
        return new Thread(runnable, Thread.currentThread().getName() + "-exec");
    }
1002699
public static ExecutorService newSingleThreadDaemonExecutor() {
        return Executors.newSingleThreadExecutor(r -> {
            Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setDaemon(true);
            return t;
        });
    }
278676
@Bean(EXECUTOR_SERVICE_BEAN_NAME)
    public ExecutorService executorService() {
        if (this.properties.getNumberOfThread() == 0) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Use cached thread pool.");
            }
            return Executors.newCachedThreadPool();
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Use {} fixed thread pool.", this.properties.getNumberOfThread());
        }
        return Executors.newFixedThreadPool(this.properties.getNumberOfThread());
    }
380784
public static ThreadFactory getThreadFactory(
            final String groupName,
            final String name,
            final int stackSize,
            final boolean incrementThreadNames,
            final Queue<String> coreList) {
        ThreadGroup group = null;
        if (groupName != null) {
            group = new ThreadGroup(Thread.currentThread().getThreadGroup(), groupName);
        }
        final ThreadGroup finalGroup = group;

        return new ThreadFactory() {
            private final AtomicLong m_createdThreadCount = new AtomicLong(0);
            private final ThreadGroup m_group = finalGroup;
            @Override
            public synchronized Thread newThread(final Runnable r) {
                final String threadName = name +
                        (incrementThreadNames ? " - " + m_createdThreadCount.getAndIncrement() : "");
                String coreTemp = null;
                if (coreList != null && !coreList.isEmpty()) {
                    coreTemp = coreList.poll();
                }
                final String core = coreTemp;
                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        if (core != null) {
                            // Remove Affinity for now to make this dependency dissapear from the client.
                            // Goal is to remove client dependency on this class in the medium term.
                            //PosixJNAAffinity.INSTANCE.setAffinity(core);
                        }
                        try {
                            r.run();
                        } catch (Throwable t) {
                            new VoltLogger("HOST").error("Exception thrown in thread " + threadName, t);
                        } finally {
                            m_threadLocalDeallocator.run();
                        }
                    }
                };

                Thread t = new Thread(m_group, runnable, threadName, stackSize);
                t.setDaemon(true);
                return t;
            }
        };
    }
1197324
public static Executors getInstance() {
        if (instance == null) {
            synchronized (Executors.class) {
                if (instance == null) instance = new Executors();
            }
        }
        return instance;
    }
28168
def run_in_thread_pool(self, pool_size=None, func=None, *args):
        """"""
        executor = Pool(pool_size)
        return self.loop.run_in_executor(executor, func, *args)
685885
@Override
    public ServiceCache<T> build()
    {
        if (executorService != null)
        {
            return new ServiceCacheImplExt<>(discovery, name, executorService);
        }
        else
        {
            return new ServiceCacheImplExt<>(discovery, name, threadFactory);
        }
    }
1146571
public static ExecutorService build(PoolType type, ThreadFactory factory) {
        int corePoolSize, maximumPoolSize;
        int keepAliveTime = 10;
        BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();
        switch (type) {
            case Singleton:
                corePoolSize = maximumPoolSize = 1;
                break;
            case IO:
                corePoolSize = Runtime.getRuntime().availableProcessors() * 10;
                maximumPoolSize = Runtime.getRuntime().availableProcessors() * 20;
                break;
            case Calc:
                corePoolSize = maximumPoolSize = Runtime.getRuntime().availableProcessors() + 1;
                break;
            default:
                throw new IllegalArgumentException(
                    String.format("内部异常，未知线程池类型[%s]", type.toString()));
        }
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime,
            TimeUnit.SECONDS, workQueue, factory, DEFAULT_HANDLER);
    }
353785
@Nullable
    private ThreadPoolExecutor unwrapThreadPoolExecutor(ExecutorService executor, Class<?> wrapper) {
        try {
            Field e = wrapper.getDeclaredField("e");
            e.setAccessible(true);
            return (ThreadPoolExecutor) e.get(executorService);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            // Do nothing. We simply can't get to the underlying ThreadPoolExecutor.
        }
        return null;
    }
943321
def get_executor(self, create=1):
        """"""
        try:
            executor = self.executor
        except AttributeError:
            if not create:
                raise
            try:
                act = self.builder.action
            except AttributeError:
                executor = SCons.Executor.Null(targets=[self])
            else:
                executor = SCons.Executor.Executor(act,
                                                   self.env or self.builder.env,
                                                   [self.builder.overrides],
                                                   [self],
                                                   self.sources)
            self.executor = executor
        return executor
587436
public Spider thread(ExecutorService executorService, int threadNum) {
        checkIfRunning();
        this.threadNum = threadNum;
        if (threadNum <= 0) {
            throw new IllegalArgumentException("threadNum should be more than one!");
        }
        this.executorService = executorService;
        return this;
    }
821534
def executor(self) -> "ThreadPoolExecutor":
        
        if not isinstance(self.__executor, ThreadPoolExecutor) or self.__executor.is_shutdown:
            self.configure()
        return self.__executor