Java 8 ThreadPoolExecutor.AbortPolicy - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ThreadPoolExecutor.AbortPolicy class.

This code example shows how to use the following methods:
    @Before 
    public void setup() { 
        listener1 = mock(ExecutorListener.class);
        listener2 = mock(ExecutorListener.class);
        task = new HazeltaskTask<String>(UUID.randomUUID(),"1", null, (Runnable) null);
        listener = new HazeltaskThreadPoolExecutor(1,1,1,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),Executors.defaultThreadFactory(),new AbortPolicy());
         
        listener.addListener(listener1);
        listener.addListener(listener2);
    } 
     
    @Test
    public void testBeforeExecute() { 
        //when(listener1.beforeExecute(task)).thenReturn(true); 
        //when(listener2.beforeExecute(task)).thenReturn(true); 
         
        listener.beforeExecute(null, task);
         
        verify(listener1).beforeExecute(eq(task));
        verify(listener2).beforeExecute(eq(task));
5
CodeRank
This code example shows how to use the following methods:
	public static final long SELECT_TIMEOUT_NANOS = TimeUnit.MILLISECONDS
			.toNanos(DEFAULT_SELECT_TIMEOUT);
 
	public static final AtomicInteger BOSS_COUNT = new AtomicInteger();
	public static final AtomicInteger REACTOR_COUNT = new AtomicInteger();
	private static final RejectedExecutionHandler defaultHandler = new AbortPolicy();
	/** 
	 * reactor线程池资源 
	 */ 
	public static final Executor REACTOR_POOL = Executors.newCachedThreadPool();
 
	/** 
	 * 4个处server处理线程 
	 */ 
	public static final ThreadPoolExecutor DEAL_POOL = new ThreadPoolExecutor(
			4, 4, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
			defaultHandler);
 
	public static void main(String[] args) {
		System.out.println(IO_THREADS);
4
CodeRank
This code example shows how to use the following methods:
		this.queueSize = queueSize;
		 
		threadPool = new ThreadPoolExecutor(this.minThreads, this.maxThreads,
    			60, TimeUnit.SECONDS,
				new LinkedBlockingQueue<Runnable>(this.queueSize),
				new NamedThreadFactory("pool-msg-consume",true),rejectHandler == null ? new AbortPolicy() : rejectHandler);
	} 
	public void consume(Runnable task)throws RejectedExecutionException,NullPointerException {
		if(!isShutDown){
			threadPool.execute(task);
		} 
	} 
	public void shutdown(){ 
		isShutDown = true;
		try{ 
			threadPool.shutdown();
		}catch(Exception e){};//关闭的过程中抛出的异常忽略
	} 
} 
4
CodeRank
This code example shows how to use the following methods:
 
/** 
 */ 
public final class ThreadPoolUtils { 
 
    private static final RejectedExecutionHandler DEFAULT_HANDLER = new AbortPolicy(); 
 
    public static ThreadFactory createThreadFactory(String poolName) { 
        return new NamedThreadFactory(poolName); 
    } 
 
    static RejectedExecutionHandler determineHandler(RejectedExecutionHandler handler) { 
        return (handler == null ? DEFAULT_HANDLER : handler); 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:
 
	/** The thread factory. */ 
	private ThreadFactory threadFactory = Executors.defaultThreadFactory();
 
	/** The handler. */ 
	private RejectedExecutionHandler handler = new AbortPolicy();
 
	/** The executor service. */ 
	private ExecutorService executorService = null;
	 
	private static final Logger log = LoggerFactory.getLogger(ThreadPool.class); 
 
	public void init(){ 
		executorService = new ThreadPoolExecutor(
				corePoolSize,
				maximumPoolSize, 
				keepAliveTime, 
				unit, 
				workQueue,
				threadFactory, 
4
CodeRank
This code example shows how to use the following methods:
		builder.setDaemon(true);
		commandQueue = new ArrayBlockingQueue<Runnable>(MAX_TASK);
		executorService = new ThreadPoolExecutor(2, // core size
				2, // max size 
				30 * 60, // idle timeout 
				TimeUnit.SECONDS, commandQueue, builder.build(), new AbortPolicy()); // queue with a size
	} 
 
	@Override 
	public int onStartCommand(Intent intent, int flags, int startId) {
		try { 
			download(intent);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} 
		return super.onStartCommand(intent, flags, startId);
	} 
 
	public void setDownloadHandler(Handler downloadHandler) {
		this.downloadHandler = downloadHandler;
4
CodeRank
This code example shows how to use the following methods:
		this.queueSize = queueSize;
		 
		threadPool = new ThreadPoolExecutor(this.minThreads, this.maxThreads,
    			60, TimeUnit.SECONDS,
				new LinkedBlockingQueue<Runnable>(this.queueSize),
				new NamedThreadFactory("pool-msg-pull",true),rejectHandler == null ? new AbortPolicy() : rejectHandler);
	} 
	public void commit(Runnable task)throws RejectedExecutionException,NullPointerException {
		if(!isShutDown){
			threadPool.execute(task);
		} 
	} 
	public void shutdown(){ 
		isShutDown = true;
		try{ 
			threadPool.shutdown();
		}catch(Exception e){};//关闭的过程中抛出的异常忽略
	} 
} 
3
CodeRank

Related Java 8 ThreadPoolExecutor.AbortPolicy Questions & Answers:

See Code Examples for Java 8 ThreadPoolExecutor.AbortPolicy Methods: