@Test public void testExecutorName_customThreadFactory() { ThreadFactory factory = runnable -> { Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setName("foo-3"); return thread; }; assertThat(PTExecutors.getExecutorName(factory)).isEqualTo("foo"); }
@VisibleForTesting static String getExecutorName(ThreadFactory factory) { if (factory instanceof NamedThreadFactory) { return ((NamedThreadFactory) factory).getPrefix(); } String threadName = factory.newThread(Runnables.doNothing()).getName(); if (!Strings.isNullOrEmpty(threadName)) { String trimmed = THREAD_NAME_TRIMMED_CHARS.trimTrailingFrom(threadName); if (!Strings.isNullOrEmpty(trimmed)) { return trimmed; } } return "PTExecutor"; }
PTExecutors { @VisibleForTesting static String getExecutorName(ThreadFactory factory) { if (factory instanceof NamedThreadFactory) { return ((NamedThreadFactory) factory).getPrefix(); } String threadName = factory.newThread(Runnables.doNothing()).getName(); if (!Strings.isNullOrEmpty(threadName)) { String trimmed = THREAD_NAME_TRIMMED_CHARS.trimTrailingFrom(threadName); if (!Strings.isNullOrEmpty(trimmed)) { return trimmed; } } return "PTExecutor"; } }
PTExecutors { @VisibleForTesting static String getExecutorName(ThreadFactory factory) { if (factory instanceof NamedThreadFactory) { return ((NamedThreadFactory) factory).getPrefix(); } String threadName = factory.newThread(Runnables.doNothing()).getName(); if (!Strings.isNullOrEmpty(threadName)) { String trimmed = THREAD_NAME_TRIMMED_CHARS.trimTrailingFrom(threadName); if (!Strings.isNullOrEmpty(trimmed)) { return trimmed; } } return "PTExecutor"; } private  PTExecutors(); }
PTExecutors { @VisibleForTesting static String getExecutorName(ThreadFactory factory) { if (factory instanceof NamedThreadFactory) { return ((NamedThreadFactory) factory).getPrefix(); } String threadName = factory.newThread(Runnables.doNothing()).getName(); if (!Strings.isNullOrEmpty(threadName)) { String trimmed = THREAD_NAME_TRIMMED_CHARS.trimTrailingFrom(threadName); if (!Strings.isNullOrEmpty(trimmed)) { return trimmed; } } return "PTExecutor"; } private  PTExecutors(); static ExecutorService newCachedThreadPool(); static ExecutorService newCachedThreadPool(String name); @Deprecated static ExecutorService newCachedThreadPool(ThreadFactory threadFactory); @Deprecated static ExecutorService newCachedThreadPool(ThreadFactory threadFactory, int threadTimeoutMillis); @Beta static ExecutorService newCachedThreadPoolWithMaxThreads(int maxThreads, String name); static ExecutorService newFixedThreadPool(int numThreads); @Deprecated static ThreadPoolExecutor newFixedThreadPool(int numThreads, ThreadFactory threadFactory); static ExecutorService newFixedThreadPool(int numThreads, String name); static ScheduledThreadPoolExecutor newScheduledThreadPool(int corePoolSize); static ScheduledThreadPoolExecutor newScheduledThreadPool(int corePoolSize,
            ThreadFactory threadFactory); static ExecutorService newSingleThreadExecutor(); static ExecutorService newSingleThreadExecutor(boolean isDaemon); @Deprecated static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory); static ScheduledExecutorService newSingleThreadScheduledExecutor(); static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory); static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue); static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,
            ThreadFactory threadFactory); static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,
            RejectedExecutionHandler handler); @SuppressWarnings("DangerousThreadPoolExecutorUsage") static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,
            ThreadFactory threadFactory, RejectedExecutionHandler handler); static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize); static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize,
            ThreadFactory threadFactory); static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize,
            RejectedExecutionHandler handler); @SuppressWarnings("DangerousThreadPoolExecutorUsage") static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize,
            ThreadFactory threadFactory, RejectedExecutionHandler handler); static ExecutorService wrap(final String operationName, final ExecutorService executorService); static ExecutorService wrap(final ExecutorService executorService); static ScheduledExecutorService wrap(
            final String operationName,
            final ScheduledExecutorService scheduledExecutorService); static ScheduledExecutorService wrap(final ScheduledExecutorService scheduledExecutorService); static Runnable wrap(final Runnable runnable); static Runnable wrap(final String operationName, final Runnable runnable); static RunnableFuture<T> wrap(RunnableFuture<T> rf); static Callable<T> wrap(final String operationName, final Callable<? extends T> callable); static Callable<T> wrap(final Callable<? extends T> callable); static Collection<Callable<T>> wrap(
            Collection<? extends Callable<? extends T>> tasks); static ThreadFactory newNamedThreadFactory(); static ThreadFactory newNamedThreadFactory(boolean isDaemon); static ThreadFactory newNamedThreadFactory(boolean isDaemon, Class<?> classToIgnore); static ThreadFactory newThreadFactory(final String prefix, final int priority, final boolean isDaemon); }
PTExecutors { @VisibleForTesting static String getExecutorName(ThreadFactory factory) { if (factory instanceof NamedThreadFactory) { return ((NamedThreadFactory) factory).getPrefix(); } String threadName = factory.newThread(Runnables.doNothing()).getName(); if (!Strings.isNullOrEmpty(threadName)) { String trimmed = THREAD_NAME_TRIMMED_CHARS.trimTrailingFrom(threadName); if (!Strings.isNullOrEmpty(trimmed)) { return trimmed; } } return "PTExecutor"; } private  PTExecutors(); static ExecutorService newCachedThreadPool(); static ExecutorService newCachedThreadPool(String name); @Deprecated static ExecutorService newCachedThreadPool(ThreadFactory threadFactory); @Deprecated static ExecutorService newCachedThreadPool(ThreadFactory threadFactory, int threadTimeoutMillis); @Beta static ExecutorService newCachedThreadPoolWithMaxThreads(int maxThreads, String name); static ExecutorService newFixedThreadPool(int numThreads); @Deprecated static ThreadPoolExecutor newFixedThreadPool(int numThreads, ThreadFactory threadFactory); static ExecutorService newFixedThreadPool(int numThreads, String name); static ScheduledThreadPoolExecutor newScheduledThreadPool(int corePoolSize); static ScheduledThreadPoolExecutor newScheduledThreadPool(int corePoolSize,
            ThreadFactory threadFactory); static ExecutorService newSingleThreadExecutor(); static ExecutorService newSingleThreadExecutor(boolean isDaemon); @Deprecated static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory); static ScheduledExecutorService newSingleThreadScheduledExecutor(); static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory); static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue); static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,
            ThreadFactory threadFactory); static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,
            RejectedExecutionHandler handler); @SuppressWarnings("DangerousThreadPoolExecutorUsage") static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
            long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue,
            ThreadFactory threadFactory, RejectedExecutionHandler handler); static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize); static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize,
            ThreadFactory threadFactory); static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize,
            RejectedExecutionHandler handler); @SuppressWarnings("DangerousThreadPoolExecutorUsage") static ScheduledThreadPoolExecutor newScheduledThreadPoolExecutor(int corePoolSize,
            ThreadFactory threadFactory, RejectedExecutionHandler handler); static ExecutorService wrap(final String operationName, final ExecutorService executorService); static ExecutorService wrap(final ExecutorService executorService); static ScheduledExecutorService wrap(
            final String operationName,
            final ScheduledExecutorService scheduledExecutorService); static ScheduledExecutorService wrap(final ScheduledExecutorService scheduledExecutorService); static Runnable wrap(final Runnable runnable); static Runnable wrap(final String operationName, final Runnable runnable); static RunnableFuture<T> wrap(RunnableFuture<T> rf); static Callable<T> wrap(final String operationName, final Callable<? extends T> callable); static Callable<T> wrap(final Callable<? extends T> callable); static Collection<Callable<T>> wrap(
            Collection<? extends Callable<? extends T>> tasks); static ThreadFactory newNamedThreadFactory(); static ThreadFactory newNamedThreadFactory(boolean isDaemon); static ThreadFactory newNamedThreadFactory(boolean isDaemon, Class<?> classToIgnore); static ThreadFactory newThreadFactory(final String prefix, final int priority, final boolean isDaemon);  }