Refine search
BlockingQueue<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<Runnable>( 100); ExecutorService executorService = new ThreadPoolExecutor(1, 10, 30, TimeUnit.SECONDS, linkedBlockingDeque, new ThreadPoolExecutor.CallerRunsPolicy());
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 WorkerPool(int numThreads) { processor = new ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(128)); processor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); }
/** * 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(); }
@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(); }
@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()); }
public WorkerPool(int numThreads) { processor = new ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(128)); processor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); }
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; }
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); }
public DiffApplier(int diffParallelism, FileSource source, FileDestination destination) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(destination); this.diffsFailedPaths = new ConcurrentSkipListSet<>(); this.refactoredPaths = Sets.newConcurrentHashSet(); this.source = source; this.destination = destination; this.completedFiles = new AtomicInteger(0); this.stopwatch = Stopwatch.createUnstarted(); // configure a bounded queue and a rejectedexecutionpolicy. // In this case CallerRuns may be appropriate. this.workerService = new ThreadPoolExecutor( 0, diffParallelism, 5, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50), new ThreadPoolExecutor.CallerRunsPolicy()); }
private ExecutorService createThreadPool() { int threads = getNumberOfPopulationWorkers(); BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>( TASK_QUEUE_SIZE ); ThreadFactory threadFactory = daemon( FLUSH_THREAD_NAME_PREFIX ); RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); return new ThreadPoolExecutor( threads, threads, 0L, TimeUnit.MILLISECONDS, workQueue, threadFactory, rejectedExecutionHandler ); }
@Override public void start() { LOG.info( "Using {} as call queue; handlerCount={}; maxQueueLength={}; rsReportHandlerCount={}; " + "rsReportMaxQueueLength={}", this.getClass().getSimpleName(), handlerCount, maxQueueLength, rsReportHandlerCount, rsRsreportMaxQueueLength); this.executor = new ThreadPoolExecutor(handlerCount, handlerCount, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(maxQueueLength), new DaemonThreadFactory("MasterFifoRpcScheduler.call.handler"), new ThreadPoolExecutor.CallerRunsPolicy()); this.rsReportExecutor = new ThreadPoolExecutor(rsReportHandlerCount, rsReportHandlerCount, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(rsRsreportMaxQueueLength), new DaemonThreadFactory("MasterFifoRpcScheduler.RSReport.handler"), new ThreadPoolExecutor.CallerRunsPolicy()); }
@Override protected void processArguments(LinkedList<PathData> args) throws IOException { executor = new ThreadPoolExecutor(numThreads, numThreads, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1024), new ThreadPoolExecutor.CallerRunsPolicy()); super.processArguments(args); // issue the command and then wait for it to finish executor.shutdown(); try { executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES); } catch (InterruptedException e) { executor.shutdownNow(); displayError(e); Thread.currentThread().interrupt(); } }
mPool = new ThreadPoolExecutor(threads, threads, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(threads * 2), new ThreadPoolExecutor.CallerRunsPolicy()); mMessages = new LinkedBlockingQueue<>(); mExceptions = new ConcurrentLinkedQueue<>();
protected void initAsyncJobExecutionThreadPool() { if (threadFactory == null) { log.warn("A managed thread factory was not found, falling back to self-managed threads"); super.initAsyncJobExecutionThreadPool(); } else { if (threadPoolQueue == null) { log.info("Creating thread pool queue of size {}", queueSize); threadPoolQueue = new ArrayBlockingQueue<Runnable>(queueSize); } if (executorService == null) { log.info("Creating executor service with corePoolSize {}, maxPoolSize {} and keepAliveTime {}", corePoolSize, maxPoolSize, keepAliveTime); ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, threadPoolQueue, threadFactory); threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executorService = threadPoolExecutor; } startJobAcquisitionThread(); } } }
/** * Creates an instance of this class. * * @param nThreads number of threads in the executor used to assist the selector loop and run completion handlers. */ public AsynchronousTlsChannelGroup(final int nThreads) { try { selector = Selector.open(); } catch (IOException e) { throw new RuntimeException(e); } timeoutExecutor.setRemoveOnCancelPolicy(true); this.executor = new ThreadPoolExecutor( nThreads, nThreads, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(nThreads * QUEUE_LENGTH_MULTIPLIER), new ThreadFactory() { @Override public Thread newThread(final Runnable runnable) { return new Thread(runnable, format("async-channel-group-%d-handler-executor", id)); } }, new ThreadPoolExecutor.CallerRunsPolicy()); selectorThread.start(); }
/** * Returns a brand new ExecutorService using the specified poolName with the specified maximum thread pool size. The * same poolName may be used more than once resulting in multiple pools with the same name. * <p> * The pool will be initialised with newPoolSize threads. If that number of threads are in use and another thread * is requested, the pool will reject execution and the submitting thread will execute the task. */ public static ExecutorService newPooledExecutor(int newPoolSize, String poolName, boolean useDaemonThreads) { return new ThreadPoolExecutor( newPoolSize, newPoolSize, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new CollectionsThreadFactory(poolName, useDaemonThreads), new ThreadPoolExecutor.CallerRunsPolicy()); }
/** * Returns a brand new ExecutorService using the specified poolName with the specified maximum thread pool size. The * same poolName may be used more than once resulting in multiple pools with the same name. * <p> * The pool will be initialised with newPoolSize threads. If that number of threads are in use and another thread * is requested, the pool will reject execution and the submitting thread will execute the task. */ public static ExecutorService newPooledExecutor(int newPoolSize, String poolName, boolean useDaemonThreads) { return new ThreadPoolExecutor( newPoolSize, newPoolSize, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), new CollectionsThreadFactory(poolName, useDaemonThreads), new ThreadPoolExecutor.CallerRunsPolicy()); }
/** * Returns a brand new ExecutorService using the specified poolName with the specified maximum thread pool size. The * same poolName may be used more than once resulting in multiple pools with the same name. * <p> * The pool will be initialised with newPoolSize threads. If that number of threads are in use and another thread * is requested, the pool will reject execution and the submitting thread will execute the task. */ public static ExecutorService newPooledExecutor(int newPoolSize, String poolName, boolean useDaemonThreads) { return new ThreadPoolExecutor( newPoolSize, newPoolSize, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), new CollectionsThreadFactory(poolName, useDaemonThreads), new ThreadPoolExecutor.CallerRunsPolicy()); }
public void start() { super.start(); executorName = this.getClass().getSimpleName() + "-" + context.getTableMeta().getFullName(); if (executor == null) { executor = new ThreadPoolExecutor(threadSize, threadSize, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(threadSize * 2), new NamedThreadFactory(executorName), new ThreadPoolExecutor.CallerRunsPolicy()); } }