{"record":{"id":"96ed0980938e6a6e","repo":"stanfordnlp/CoreNLP","slug":"couldn-t-submit-item-to-threadpool","errorCode":null,"errorMessage":"Couldn't submit item to threadpool: ","messagePattern":"Couldn't submit item to threadpool: ","errorType":"exception","errorClass":"RejectedExecutionException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/concurrent/MulticoreWrapper.java","lineNumber":136,"sourceCode":"        threadPool.getQueue().size(),\n        outputQueue.size(),\n        idleProcessors.size());\n  }\n  \n  /**\n   * Allocate instance to a process and return. This call blocks until item\n   * can be assigned to a thread.\n   *\n   * @param item Input to a Processor\n   * @throws RejectedExecutionException -- A RuntimeException when there is an\n   * uncaught exception in the queue. Resolution is for the calling class to shutdown\n   * the wrapper and create a new threadpool.\n   * \n   */\n  public synchronized void put(I item) throws RejectedExecutionException {\n    Integer procId = getProcessor();\n    if (procId == null) {\n      throw new RejectedExecutionException(\"Couldn't submit item to threadpool: \" + item);\n    }\n    final int itemId = submittedItemCounter++;\n    CallableJob<I,O> job = new CallableJob<>(item, itemId, processorList.get(procId), procId, callback);\n    threadPool.submit(job);\n  }\n\n  /**\n   * Returns the next available thread id.  Subclasses may wish to\n   * override this, for example if they implement a timeout\n   */\n  Integer getProcessor() {\n    try {\n      return idleProcessors.take();\n    } catch (InterruptedException e) {\n      throw new RuntimeInterruptedException(e);\n    }\n  }\n  ","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/concurrent/MulticoreWrapper.java#L118-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Wait for queued items to drain (call process(item)/join() periodically) before submitting more","Do not call put() after join() unless you re-create or properly restart the MulticoreWrapper","Ensure only one thread submits to the wrapper (put is synchronized; getProcessor can still return null during shutdown)","Catch RejectedExecutionException and retry after join() if the item must not be lost"],"exampleFix":"// before\nfor (String s : inputs) { wrapper.put(s); }\nwrapper.join();\nwrapper.put(extra);\n// after\nfor (String s : inputs) { wrapper.process(s); }\nwrapper.join();\n// submit extra via a new wrapper or before join:\nwrapper.put(extra);\nwrapper.join();","handlingStrategy":"try-catch","validationCode":"// Drain before large submissions\nif (wrapper.numObjectsToProcess() > threshold) wrapper.join();","typeGuard":null,"tryCatchPattern":"boolean submitted = false;\nwhile (!submitted) {\n  try {\n    wrapper.put(item);\n    submitted = true;\n  } catch (RejectedExecutionException e) {\n    wrapper.join(); // drain and let the pool rebuild, then retry\n  }\n}","preventionTips":["Call process(item)/join() periodically instead of putting unbounded numbers of items","Never call put() after the wrapper has been joined/terminated unless you re-create it","Keep submissions on a single thread or serialize them","Watch for shutdown hooks that may kill the pool mid-run"],"tags":["concurrency","threadpool","rejected-execution"],"backgroundTag":"thread-pool-shutdown","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}