zoukankan      html  css  js  c++  java
  • 开发中的异常收集(持续更新中...)

    java.lang.ArithmeticException: divide by zero

    算数异常,除数为0

     java.util.concurrent.RejectedExecutionException: pool=128/128, queue=10/10

    AsyncTask引发的异常,线程池已满拒绝过剩task

    默认的线程池会引发这个异常

        AsyncTask.class
    ...
     public static final Executor THREAD_POOL_EXECUTOR
                = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
                        TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory);
    
    
    ...
    public ThreadPoolExecutor(int corePoolSize,
                                  int maximumPoolSize,
                                  long keepAliveTime,
                                  TimeUnit unit,
                                  BlockingQueue<Runnable> workQueue) {
            this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
                 Executors.defaultThreadFactory(), defaultHandler);
        }
    ...
        private static final RejectedExecutionHandler defaultHandler =
            new AbortPolicy();
    ...
        public static class AbortPolicy implements RejectedExecutionHandler {
            /**
             * Creates an {@code AbortPolicy}.
             */
            public AbortPolicy() { }
    
            /**
             * Always throws RejectedExecutionException.
             *
             * @param r the runnable task requested to be executed
             * @param e the executor attempting to execute this task
             * @throws RejectedExecutionException always
             */
            public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
                throw new RejectedExecutionException("Task " + r.toString() +
                                                     " rejected from " +
                                                     e.toString());
            }
        }
    ...
    

      解决办法:自定义 RejectedExecutionHandler或者调用其他实现类

      public static final Executor THREAD_POOL_EXECUTOR
                = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
                TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory, new ThreadPoolExecutor.DiscardOldestPolicy());
    

      

  • 相关阅读:
    C#中的代理(Delegate)
    动态栈C语言
    AMS算法
    动态队列实现C语言
    带头结点的循环单链表C语言
    静态栈C语言
    不带头结点的单链表C语言实现
    带头结点的双向循环链表C语言
    带头节点的单链表C语言实现
    使用函数指针模拟C++多态
  • 原文地址:https://www.cnblogs.com/wjw334/p/6795015.html
Copyright © 2011-2022 走看看