Code example for ThreadPoolExecutor

Methods: execute

0
    private static final int DEFAULT_POOL_SIZE = 2;
 
    private ThreadPoolExecutor executor = new ThreadPoolExecutor(DEFAULT_POOL_SIZE, DEFAULT_POOL_SIZE, 5, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<Runnable>());
 
    public void process(PacketChannelEvent<T> event) {
        executor.execute(event);
    } 
 
    public void setPoolSize(int poolSize) {
        executor.setMaximumPoolSize(poolSize);
        executor.setCorePoolSize(poolSize);
    } 
 
    public int getQueueSize() { 
        return executor.getQueue().size();
    } 
 
    public int getActiveCount() { 
        return executor.getActiveCount();
    }