stanfordnlp/CoreNLP · error · RejectedExecutionException

Couldn't submit item to threadpool:

Error message

Couldn't submit item to threadpool: 

What it means

MulticoreWrapper.put(I) throws RejectedExecutionException when getProcessor() returns null, i.e. no thread pool slot could be allocated to accept the item. The message includes the rejected item. Internally the wrapper shuts down and rebuilds its threadpool when the job queue backs up; submitting during that transition, or after shutdown, gets rejected.

Solutions

  1. Wait for queued items to drain (call process(item)/join() periodically) before submitting more
  2. Do not call put() after join() unless you re-create or properly restart the MulticoreWrapper
  3. Ensure only one thread submits to the wrapper (put is synchronized; getProcessor can still return null during shutdown)
  4. Catch RejectedExecutionException and retry after join() if the item must not be lost

Example fix

// before
for (String s : inputs) { wrapper.put(s); }
wrapper.join();
wrapper.put(extra);
// after
for (String s : inputs) { wrapper.process(s); }
wrapper.join();
// submit extra via a new wrapper or before join:
wrapper.put(extra);
wrapper.join();
Defensive patterns

Strategy: try-catch

Validate before calling

// Drain before large submissions
if (wrapper.numObjectsToProcess() > threshold) wrapper.join();

Try / catch

boolean submitted = false;
while (!submitted) {
  try {
    wrapper.put(item);
    submitted = true;
  } catch (RejectedExecutionException e) {
    wrapper.join(); // drain and let the pool rebuild, then retry
  }
}

Prevention

When it happens

Trigger: Calling put(item) after the threadpool has been shut down (e.g. after join()/terminating the wrapper, or calling put from multiple threads across a shutdown boundary), or submitting more items than the bounded queue can accept while the pool is being recreated.

Common situations: Pipelined NLP/classifier loops that call join() then keep calling put() without re-creating the wrapper; mixing process()/join() and raw put() incompatibly; JVM shutting down (shutdown hooks) while jobs are still submitted.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/96ed0980938e6a6e. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/concurrent/MulticoreWrapper.java:136

        threadPool.getQueue().size(),
        outputQueue.size(),
        idleProcessors.size());
  }
  
  /**
   * Allocate instance to a process and return. This call blocks until item
   * can be assigned to a thread.
   *
   * @param item Input to a Processor
   * @throws RejectedExecutionException -- A RuntimeException when there is an
   * uncaught exception in the queue. Resolution is for the calling class to shutdown
   * the wrapper and create a new threadpool.
   * 
   */
  public synchronized void put(I item) throws RejectedExecutionException {
    Integer procId = getProcessor();
    if (procId == null) {
      throw new RejectedExecutionException("Couldn't submit item to threadpool: " + item);
    }
    final int itemId = submittedItemCounter++;
    CallableJob<I,O> job = new CallableJob<>(item, itemId, processorList.get(procId), procId, callback);
    threadPool.submit(job);
  }

  /**
   * Returns the next available thread id.  Subclasses may wish to
   * override this, for example if they implement a timeout
   */
  Integer getProcessor() {
    try {
      return idleProcessors.take();
    } catch (InterruptedException e) {
      throw new RuntimeInterruptedException(e);
    }
  }
  

View on GitHub (pinned to 1b7edd19c4)