小编MMP*_*Pgm的帖子

未来任务从ThreadPoolExecutor中被拒绝

我有一个ThreadPoolExecutor,我向它提交任务.

private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
Run Code Online (Sandbox Code Playgroud)

此代码提交RunnableThreadPoolExecutor.

 protected void waitAndSweep(final String symbol) {

    runnable = new Runnable() {
      public void run() { /* irrelevant code */ }
    };

    try {
      Future<?> self = threadPoolExecutor.submit(runnable);
      futures.add(self);
    } catch (RejectedExecutionException re) {
      /* this exception will be thrown when wait and sweep is called more than twice.
       * threadPoolExecutor can have one running task and one waiting task.
       */
    } …
Run Code Online (Sandbox Code Playgroud)

java java.util.concurrent

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

java.util.concurrent ×1