Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[Improvement] Avoid potential OOM in SessionPoolExample by replacing unbounded thread pool

未關閉
#17,016 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
54/100
Issue 類型
重構
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
java
領域
backend

研究方向

開啟 example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java,檢查第 74 行附近的 ExecutorService 初始化。確認目前固定執行緒池的佇列如何運作,然後驗證範例使用有界容量,並且不依賴無界佇列即可提供背壓。

由索引模型根據 Issue 內容生成。

描述

Search before asking
  • I searched in the issues and found nothing similar.
Version

Master

Describe the bug and provide the minimal reproduce step

Description:
In example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java, the ExecutorService is initialized using Executors.newFixedThreadPool(10) (Line 74).

Problem:
Executors.newFixedThreadPool uses an unbounded LinkedBlockingQueue (capacity: Integer.MAX_VALUE) by default. As this is an official example, users often copy-paste this code for production. In high-throughput write scenarios, if the production rate exceeds the consumption rate, tasks accumulate indefinitely in the queue, leading to OutOfMemoryError: Java heap space.

Code Location:
// org.apache.iotdb.SessionPoolExample.java
service = Executors.newFixedThreadPool(10); // Unbounded Queue risk

What did you expect to see?

Official examples should demonstrate best practices by using bounded queues to ensure system stability. The thread pool should provide backpressure (block or reject) when the queue is full, preventing memory exhaustion.

What did you see instead?

The example uses an unbounded queue pattern (UBSCQ), which creates a hidden memory leak risk for downstream users who adopt this code snippet.

Anything else?

Suggested Fix: Replace the factory method with a custom ThreadPoolExecutor using a bounded queue (e.g., ArrayBlockingQueue).

Proposed Code:
service = new ThreadPoolExecutor(
10, 10, 0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(1000) // Bounded capacity
);

Are you willing to submit a PR?
  • I'm willing to submit a PR!
主要語言
Java
星號
6.4k
分支
1.2k
平均合併
1 天 20 小時
30 天內合併 PR
137

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

apache/iotdb 的其他 Issue

查看 apache/iotdb 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。