有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓致命的例外:java。util。同时发生的拒绝执行异常

当我试图提交服务时,我遇到了下面提到的错误

Fatal Exception: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@428a4d70 rejected from java.util.concurrent.ThreadPoolExecutor@427c1228[Shutting down, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 12]

这是我以前提交的代码

public class RunnablesQueue {
    private final int poolSize;
    private String name;
    private ExecutorService serialExecutor;

    public RunnablesQueue(String name) {
        this.name = name;
        this.poolSize = 1;
    }

    public RunnablesQueue(String name, int poolSize) {
        this.name = name;
        this.poolSize = poolSize;
    }

    /**
     * Offer a runnable to be queued for execution
     *
     * @param runnable Runnable to offer.
     */
    public void offer(final Runnable runnable) {
        serialExecutor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    Log.d("Running item from queue: " + name);
                    runnable.run();
                } catch (Exception e) {
                    Log.e(e, "Execution failed");
                }
            }
        });
    }

    /**
     * Start the queue.
     */
    public void start() {
        if (serialExecutor == null || serialExecutor.isShutdown()) {
            serialExecutor = Executors.newFixedThreadPool(poolSize);
        }
    }

    /**
     * Shutdown the queue.
     */
    public void shutdown() {
        if (serialExecutor != null && !serialExecutor.isShutdown()) {
            serialExecutor.shutdownNow();
        }
    }
 }

共 (0) 个答案