Creates a single-threaded executor that is registered by this class in order to shut it down later (when it
becomes necessary).

@return a new background executor
422789
public static ExecutorService createBackgroundExecutor() {
		final ExecutorService executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory(DEFAULT_BACKGROUND_EXECUTOR_NAME));
		BACKGROUND_EXECUTORS.add(executor);
		return executor;
	}
472462
public com.bazaarvoice.ostrich.AsyncServicePool<S> buildAsync() {
        ServicePool<S> pool = buildInternal();

        boolean shutdownAsyncExecutorOnClose = (_asyncExecutor == null);
        if (_asyncExecutor == null) {
            ThreadFactory threadFactory = new ThreadFactoryBuilder()
                    .setNameFormat(_serviceName + "-AsyncExecutorThread-%d")
                    .setDaemon(true)
                    .build();
            _asyncExecutor = Executors.newCachedThreadPool(threadFactory);
        }

        return new AsyncServicePool<>(Ticker.systemTicker(), pool, true, _asyncExecutor,
                shutdownAsyncExecutorOnClose, _metrics);
    }
1016925
public static ThreadDump create()
  {
    ThreadDump threadDump = _threadDumpRef.get();
    
    if (threadDump == null) {
      threadDump = new ThreadDumpPro();
      
      _threadDumpRef.compareAndSet(null, threadDump);
      threadDump = _threadDumpRef.get();
    }
    
    return threadDump;
  }
1080882
public static Executor newThreadExecutor(final ThreadFactory threadFactory) {
    return new Executor() {

      final AtomicInteger id = new AtomicInteger(0);

      @Override
      public void execute(Runnable command) {
        Thread t = threadFactory.newThread(command);
        t.start();
      }
    };
  }
1287257
@NotNull
    public CommandExecutor build() {
        return new DefaultCommandExecutor(
                logger!=null ? logger : defaultLogger,
                cache!=null ? cache : new ExecutorCache(),
                extensions==null ? Collections.<ModeExtension>emptyList() : extensions
        );
    }
28038
public static ScheduledThreadPoolExecutor buildDefaultTimeoutThreadPool(final String name) {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5, getThreadFactory(name));
        safeSetRemoveOnCancel(executor);
        executor.setKeepAliveTime(5, TimeUnit.SECONDS);
        executor.allowCoreThreadTimeOut(true);

        return executor;
    }
1352266
private static ScheduledExecutorService newSingleThreadScheduler() {
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        EXECUTORS.add(scheduledExecutorService);
        return scheduledExecutorService;
    }
268674
public static Future doInBackground(Callable callable) {
        final ExecutorService executor = Executors.newSingleThreadExecutor();
        Future future = executor.submit(callable);

        if(executor.isTerminated()) {
            executor.shutdown();
        }

        return future;
    }
1182254
public static MapReduceExecutor getMapReduceExecutor() {
    if (executor == null) {
      // Default to using a local executor with one thread per CPU.
      executor = new LocalMapReduceExecutor(
          Runtime.getRuntime().availableProcessors(), 20);
    }
    return executor;
  }
144304
static <I, O> CipherExecutor<I, O> getInstance() {
        if (INSTANCE == null) {
            synchronized (NoOpCipherExecutor.class) {
                if (INSTANCE == null) {
                    INSTANCE = new NoOpCipherExecutor<>();
                }
            }
        }
        return INSTANCE;
    }
442337
@Nonnull
    public static synchronized ScheduledExecutorService get() {
        if (executorService == null) {
            // corePoolSize is set to 10, but will only be created if needed.
            // ScheduledThreadPoolExecutor "acts as a fixed-sized pool using corePoolSize threads"
            // TODO consider also wrapping in ContextResettingExecutorService
             executorService = new ImpersonatingScheduledExecutorService(new ErrorLoggingScheduledThreadPoolExecutor(10, new NamingThreadFactory(new ClassLoaderSanityThreadFactory(new DaemonThreadFactory()), "jenkins.util.Timer")), ACL.SYSTEM);
        }
        return executorService;
    }
113194
public Thread getExecutingThread() {
		synchronized (this) {

			if (this.executingThread == null) {
				if (this.taskName == null) {
					this.executingThread = new Thread(this);
				}
				else {
					this.executingThread = new Thread(this, getTaskNameWithIndex());
				}
			}

			return this.executingThread;
		}
	}
923854
public static KriptonTaskExecutor getInstance() {
		if (sInstance != null) {
			return sInstance;
		}
		synchronized (KriptonTaskExecutor.class) {
			if (sInstance == null) {
				sInstance = new KriptonTaskExecutor();
			}
		}
		return sInstance;
	}
1016406
protected ExecutorService createDefaultExecutorService(ConcurrentAsyncExecutorProvider provider) {
        final int corePoolSize = 0;
        Integer maximumPoolSize = provider != null ? provider.provideMaxPoolSize() : null;
        if (maximumPoolSize == null) {
            maximumPoolSize = 10;
        }
        final long keepAliveTime = 60L;
        final TimeUnit seconds = TimeUnit.SECONDS;
        final BlockingQueue<Runnable> workQueue = createDefaultBlockingQueue();
        final RejectedExecutionHandler rejected = createRejectedExecutionHandler();
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, seconds, workQueue, rejected);
    }
383170
public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize,
                                                         int maximumPoolSize,
                                                         BlockingQueue<Runnable> queue) {
        return new ThreadPoolExecutor(corePoolSize,
            maximumPoolSize,
            DateUtils.MILLISECONDS_PER_MINUTE,
            TimeUnit.MILLISECONDS,
            queue);
    }
976657
public static ServiceAdapter<ExecutorService> forExecutorService() {
		return new SimpleServiceAdapter<ExecutorService>(false, true) {
			@Override
			protected void start(ExecutorService instance) {
			}

			@Override
			protected void stop(ExecutorService instance) throws Exception {
				List<Runnable> runnables = instance.shutdownNow();
				if (!runnables.isEmpty()) {
					logger.warn("Cancelled tasks: " + runnables);
				}
				if (!instance.isTerminated()) {
					logger.warn("Awaiting termination of " + instance + " ...");
					instance.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
				}
			}
		};
	}
1065133
public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize,
                                                         int maximumPoolSize) {
        return new ThreadPoolExecutor(corePoolSize,
            maximumPoolSize,
            DateUtils.MILLISECONDS_PER_MINUTE,
            TimeUnit.MILLISECONDS,
            new SynchronousQueue<Runnable>());
    }