public static ExecutorService newFixedThreadPool(int nThreads) { return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); } public static ExecutorService newCachedThreadPool() { return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); }
executor = new ThreadPoolExecutor( this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS, queue, threadFactory, rejectedExecutionHandler) { executor = new ThreadPoolExecutor( this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS, queue, threadFactory, rejectedExecutionHandler); executor.allowCoreThreadTimeOut(true);
BlockingQueue<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<Runnable>( 100); ExecutorService executorService = new ThreadPoolExecutor(1, 10, 30, TimeUnit.SECONDS, linkedBlockingDeque, new ThreadPoolExecutor.CallerRunsPolicy());
private ThreadPoolExecutor createExecutor() { ThreadPoolExecutor exec = new ThreadPoolExecutor(0, 2, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), factory); exec.allowCoreThreadTimeOut(true); return exec; } }
private static ExecutorService getDefaultExecutor() { return new ThreadPoolExecutor(0, 1, KEEPALIVE_TIME, KEEPALIVE_UNIT, new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY); } }
/** * Create a new CachedThreadPool with a bounded number as the maximum * thread size in the pool. * * @param maxCachedThread the maximum thread could be created in the pool * @param timeout the maximum time to wait * @param unit the time unit of the timeout argument * @param threadFactory the factory to use when creating new threads * @return threadPoolExecutor the cachedThreadPool with a bounded number * as the maximum thread size in the pool. */ public static ThreadPoolExecutor getBoundedCachedThreadPool( int maxCachedThread, long timeout, TimeUnit unit, ThreadFactory threadFactory) { ThreadPoolExecutor boundedCachedThreadPool = new ThreadPoolExecutor(maxCachedThread, maxCachedThread, timeout, unit, new LinkedBlockingQueue<>(), threadFactory); // allow the core pool threads timeout and terminate boundedCachedThreadPool.allowCoreThreadTimeOut(true); return boundedCachedThreadPool; }
private void internalInit() { if (mThreadPoolExecutor != null && !mThreadPoolExecutor.isShutdown()) { mThreadPoolExecutor.shutdownNow(); } mThreadPoolExecutor = new ThreadPoolExecutor( CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory); mThreadPoolExecutor.allowCoreThreadTimeOut(true); }
public class ImageManager { BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(blockQueueSize); RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); private ExecutorService executorService = new ThreadPoolExecutor(numOfThread, numOfThread, 0L, TimeUnit.MILLISECONDS, blockingQueue, rejectedExecutionHandler); private int downloadThumbnail(String fileListPath){ executorService.submit(new yourRunnable()); } }
public static ExecutorService newFixedThreadPool(int nThreads) { return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); }
public static ExecutorService newFixedThreadPoolWithFeedSize(String threadName, int poolSize, int feedSize) { LinkedBlockingQueue<Runnable> feed = new LinkedBlockingQueue<>(feedSize); RejectedExecutionHandler rejectionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); ThreadFactory threadFactory = new LoggingThreadFactory(threadName); ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize, poolSize, 10, SECONDS, feed, threadFactory, rejectionHandler); executor.allowCoreThreadTimeOut(true); return executor; }
private ThreadPoolExecutor createExecutor() { ThreadPoolExecutor exec = new ThreadPoolExecutor(0, Integer.MAX_VALUE, getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory); exec.allowCoreThreadTimeOut(true); return exec; }
/** * Create a scheduler that executes tasks in dynamically adjustable intervals */ public TimeScheduler3() { pool=new ThreadPoolExecutor(4, 10, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(100), Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); start(); }
public ThreadPoolExecutor build() { BlockingQueue<Runnable> queue = null; if (queueSize < 1) { queue = new LinkedBlockingQueue<Runnable>(); } else { queue = new ArrayBlockingQueue<Runnable>(queueSize); } threadFactory = createThreadFactory(threadFactory, threadNamePrefix, daemon); if (rejectHandler == null) { rejectHandler = defaultRejectHandler; } return new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS, queue, threadFactory, rejectHandler); } }
/** * Creates a new instance of {@link AsyncUfsAbsentPathCache}. * * @param mountTable the mount table * @param numThreads the maximum number of threads for the async thread pool */ public AsyncUfsAbsentPathCache(MountTable mountTable, int numThreads) { mMountTable = mountTable; mCurrentPaths = new ConcurrentHashMap<>(8, 0.95f, 8); mCache = CacheBuilder.newBuilder().maximumSize(MAX_PATHS).build(); mThreads = numThreads; mPool = new ThreadPoolExecutor(mThreads, mThreads, THREAD_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), ThreadFactoryUtils.build("UFS-Absent-Path-Cache-%d", true)); mPool.allowCoreThreadTimeOut(true); }
this.connectionExecutor = new ThreadPoolExecutor(3, quorumCnxnThreadsSize, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), daemonThFactory); this.connectionExecutor.allowCoreThreadTimeOut(true);
@ManagedOperation public void start() throws IOException, MalformedObjectNameException, MBeanRegistrationException { srv_sock=new ServerSocket(port, 50, bind_addr); if(thread_pool == null) { thread_pool=new ThreadPoolExecutor(core_threads, max_threads, idle_time, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), new ThreadPoolExecutor.CallerRunsPolicy()); // thread_pool=new DirectExecutor(); } if(thread == null || !thread.isAlive()) { thread=new Thread(this, "Acceptor"); thread.start(); } start_time=System.currentTimeMillis(); }
public void start() { executorService = new ThreadPoolExecutor( corePoolSize, maximumPoolSize, keepAliveTimeMillis, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(queueCapacity)); }
private static ThreadPoolExecutor createDelegate() { ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( MAX_THREAD_COUNT, MAX_THREAD_COUNT, KEEP_ALIVE_TIME_IN_MINUTES, MINUTES, new LinkedBlockingQueue<>(UNLIMITED_QUEUE), new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("SQ_async-%d") .setUncaughtExceptionHandler(((t, e) -> LOG.error("Thread " + t + " failed unexpectedly", e))) .build()); threadPoolExecutor.allowCoreThreadTimeOut(true); return threadPoolExecutor; }
public AsyncNoBundler() { thread_pool=new ThreadPoolExecutor(0, max_threads, 30000, TimeUnit.MICROSECONDS, new SynchronousQueue<>(), new DefaultThreadFactory("async-bundler", true, true), new ThreadPoolExecutor.CallerRunsPolicy()); thread_pool.allowCoreThreadTimeOut(true); }
@Override public void start() { LOG.info("Using {} as user call queue; handlerCount={}; maxQueueLength={}", this.getClass().getSimpleName(), handlerCount, maxQueueLength); this.executor = new ThreadPoolExecutor( handlerCount, handlerCount, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(maxQueueLength), new DaemonThreadFactory("FifoRpcScheduler.handler"), new ThreadPoolExecutor.CallerRunsPolicy()); }