List of usage examples for java.util.concurrent ThreadPoolExecutor.AbortPolicy ThreadPoolExecutor.AbortPolicy
ThreadPoolExecutor.AbortPolicy
From source file:edu.wpi.checksims.util.threading.ParallelAlgorithm.java
/** * @param threads Number of threads to be used for execution *//* www. ja va2 s . c o m*/ public static void setThreadCount(int threads) { checkArgument(threads > 0, "Attempted to set number of threads to " + threads + ", but must be positive integer!"); threadCount = threads; executor.shutdown(); // Set up the executor again with the new thread count executor = new ThreadPoolExecutor(threadCount, threadCount, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new ThreadPoolExecutor.AbortPolicy()); }
From source file:com.oneops.util.ReliableExecutor.java
public ReliableExecutor(int threadPoolSize, boolean doSyncOnRejection) { this.threadPoolSize = threadPoolSize; RejectedExecutionHandler handler; if (doSyncOnRejection) { handler = new ThreadPoolExecutor.CallerRunsPolicy(); } else {// ww w . ja va 2s .com handler = new ThreadPoolExecutor.AbortPolicy(); } executors = new ThreadPoolExecutor(0, threadPoolSize, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), handler); }
From source file:org.alfresco.extension.bulkimport.impl.BulkImportThreadPoolExecutor.java
public BulkImportThreadPoolExecutor(final ThreadPauser pauser, final int threadPoolSize, final int queueCapacity, final long keepAliveTime, final TimeUnit keepAliveTimeUnit) { super(threadPoolSize <= 0 ? DEFAULT_THREAD_POOL_SIZE : threadPoolSize, // Core pool size threadPoolSize <= 0 ? DEFAULT_THREAD_POOL_SIZE : threadPoolSize, // Max pool size (same as core pool size) keepAliveTime <= 0 ? DEFAULT_KEEP_ALIVE_TIME : keepAliveTime, // Keep alive keepAliveTimeUnit == null ? DEFAULT_KEEP_ALIVE_TIME_UNIT : keepAliveTimeUnit, // Keep alive units new LinkedBlockingQueue<Runnable>(), // Queue of maximum size new BulkImportThreadFactory(), // Thread factory new ThreadPoolExecutor.AbortPolicy()); // Rejection handler (shouldn't ever be called, due to the use of a semaphone before task submission) this.queueCapacity = queueCapacity; this.pauser = pauser; final int queuePlusPoolSize = (queueCapacity <= 0 ? DEFAULT_QUEUE_CAPACITY : queueCapacity) + (threadPoolSize <= 0 ? DEFAULT_THREAD_POOL_SIZE : threadPoolSize); this.queueSemaphore = new Semaphore(queuePlusPoolSize); if (debug(log)) debug(log, "Created new bulk import thread pool." + " Thread Pool Size=" + (threadPoolSize <= 0 ? DEFAULT_THREAD_POOL_SIZE : threadPoolSize) + ", Queue Capacity=" + ((queueCapacity <= 0 ? DEFAULT_QUEUE_CAPACITY : queueCapacity) + 2) + ", Keep Alive Time=" + (keepAliveTime <= 0 ? DEFAULT_KEEP_ALIVE_TIME : keepAliveTime) + " " + String.valueOf(keepAliveTimeUnit == null ? DEFAULT_KEEP_ALIVE_TIME_UNIT : keepAliveTimeUnit)); }