美文网首页看!源码之Netty
8、看!源码之netty线程池AbstractEventExec

8、看!源码之netty线程池AbstractEventExec

作者: starskye | 来源:发表于2019-05-20 14:26 被阅读0次

    AbstractEventExecutorGroup的源码解读

    AbstractEventExecutorGroup是EventExecutorGroup的抽象实现类,因为他是抽象类所以只实现了几个方法,在讲解之前想讲述ExecutorGroup和Executor的关系,他们都是实现与EventExecutorGroup,但是他们并不一样实现与他是因为内部功能一样所以实现与这个接口,group用于对executor的管理比如关闭线程组的时候线程组会遍历管理的executor去挨个关闭。所以在阅读的api的时候不要因为他们的实现关系而乱了思维。

    //此类的方法定义在第一篇讲解结构的时候就讲解过了,而这个抽象实现并没有具体得意义都是调用next方法获取executor去执行对于的操作所以这里暂时了解他的架子即可。
    //这个抽象类并没有对executor组进行管理的操作所以此类也算是一个定义类。在讲解他的继承类的时候将会讲解此处的使用。所以暂时此类并没有任何意义。
    public abstract class AbstractEventExecutorGroup implements EventExecutorGroup {
        
        @Override
        public Future<?> submit(Runnable task) {
            return next().submit(task);
        }
    
        @Override
        public <T> Future<T> submit(Runnable task, T result) {
            return next().submit(task, result);
        }
    
        @Override
        public <T> Future<T> submit(Callable<T> task) {
            return next().submit(task);
        }
    
        @Override
        public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            return next().schedule(command, delay, unit);
        }
    
        @Override
        public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
            return next().schedule(callable, delay, unit);
        }
    
        @Override
        public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
            return next().scheduleAtFixedRate(command, initialDelay, period, unit);
        }
    
        @Override
        public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
            return next().scheduleWithFixedDelay(command, initialDelay, delay, unit);
        }
    
        @Override
        public Future<?> shutdownGracefully() {
            return shutdownGracefully(DEFAULT_SHUTDOWN_QUIET_PERIOD, DEFAULT_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS);
        }
    
        /**
         * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead.
         */
        @Override
        @Deprecated
        public abstract void shutdown();
    
        /**
         * @deprecated {@link #shutdownGracefully(long, long, TimeUnit)} or {@link #shutdownGracefully()} instead.
         */
        @Override
        @Deprecated
        public List<Runnable> shutdownNow() {
            shutdown();
            return Collections.emptyList();
        }
    
        @Override
        public <T> List<java.util.concurrent.Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
                throws InterruptedException {
            return next().invokeAll(tasks);
        }
    
        @Override
        public <T> List<java.util.concurrent.Future<T>> invokeAll(
                Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
            return next().invokeAll(tasks, timeout, unit);
        }
    
        @Override
        public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
            return next().invokeAny(tasks);
        }
    
        @Override
        public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
                throws InterruptedException, ExecutionException, TimeoutException {
            return next().invokeAny(tasks, timeout, unit);
        }
    
        @Override
        public void execute(Runnable command) {
            next().execute(command);
        }
    }
    
    

    相关文章

      网友评论

        本文标题:8、看!源码之netty线程池AbstractEventExec

        本文链接:https://www.haomeiwen.com/subject/rbdkzqtx.html