{
  "id": "java/illegal-thread-state-exception",
  "signature": "java.lang.IllegalThreadStateException",
  "signature_zh": "java.lang.IllegalThreadStateException",
  "regex": "java\\.lang\\.IllegalThreadStateException",
  "domain": "java",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Thrown when attempting to start a thread that has already been started or when the thread is in an invalid state for the requested operation.",
  "root_cause_type": "generic",
  "root_cause_zh": "当尝试启动一个已经启动的线程或线程处于请求操作无效状态时抛出。",
  "versions": [
    {
      "version": "Java 8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Thread cannot be restarted; the exception indicates a logic error that will recur.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Synchronization does not prevent calling start() on an already started thread; the check must be explicit.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Thread.stop() is deprecated and unsafe; it may leave the thread in an inconsistent state.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check the thread's state before starting: `if (thread.getState() == Thread.State.NEW) { thread.start(); }`. This ensures start() is only called once.",
      "success_rate": 0.95,
      "how": "Check the thread's state before starting: `if (thread.getState() == Thread.State.NEW) { thread.start(); }`. This ensures start() is only called once.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a thread pool (e.g., ExecutorService) instead of managing threads manually. Submit tasks to the pool, which handles thread lifecycle correctly.",
      "success_rate": 0.9,
      "how": "Use a thread pool (e.g., ExecutorService) instead of managing threads manually. Submit tasks to the pool, which handles thread lifecycle correctly.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If restarting is needed, create a new Thread instance for each execution: `thread = new Thread(task); thread.start();`.",
      "success_rate": 0.85,
      "how": "If restarting is needed, create a new Thread instance for each execution: `thread = new Thread(task); thread.start();`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Check the thread's state before starting: `if (thread.getState() == Thread.State.NEW) { thread.start(); }`. This ensures start() is only called once.",
    "Use a thread pool (e.g., ExecutorService) instead of managing threads manually. Submit tasks to the pool, which handles thread lifecycle correctly.",
    "If restarting is needed, create a new Thread instance for each execution: `thread = new Thread(task); thread.start();`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalThreadStateException.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}