This content originally appeared on DEV Community and was authored by Zaw Htut Win
ThreadPoolExecutor သုံးတဲ့ Queue က Blocking Queue အမျိုးအစားဝင်တွေထဲက ဖြစ်ပါတယ်။
ExecutorService pool = Executors.newFixedThreadPool(10);
ဒါက သူ့ default constructor ကိုခေါ်ထားတာ။
return new ThreadPoolExecutor(
nThreads, nThreads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>()
);
ThreadPoolExecutors ဆိုတာက utility class ဖြစ်ပြီးတော့ ဒီနေရာမှာ သူ့ရဲ့ Blocking Queue အမျိုးအစားက LinkedBlockingQueue ကို default အနေနဲ့သုံးတာပါ။ အထက်ဖေါ်ပြပါ code က newFixedThreadPool(10) လို့ခေါ်လိုက်ရင် ထွက်လာမယ့် Executor object ပါ။ LinkedBlockingQueue ကိုနောက်များမှ ဖေါ်ပြပါ့မယ်။
ExecutorService executor = Executors.newCachedThreadPool();
ဒါက သူ့ default constructor ကိုခေါ်ထားတာ။
return new ThreadPoolExecutor(
0, // corePoolSize
Integer.MAX_VALUE, // maximumPoolSize
60L, TimeUnit.SECONDS, // idle threads die after 60s
new SynchronousQueue<Runnable>() // workQueue
);
ဒီတခါလည်း ThreadPoolExecutor ကို သုံးပြီး SynchronousQueue ကို default အနေနဲ့ သုံးထားတာကို တွေ့ရမှဖြစ်ပါတယ်။
ExecutorService executor = Executors.newSingleThreadExecutor();
ဒါက သူ့ default constructor ကိုခေါ်ထားတာ။
return new FinalizableDelegatedExecutorService(
new ThreadPoolExecutor(
1, // corePoolSize
1, // maximumPoolSize
0L, TimeUnit.MILLISECONDS, // no idle timeout
new LinkedBlockingQueue<Runnable>() // task queue
)
);
ဒါက ThreadPoolExecutorService ထဲက သူ့ရဲ့ implementation ဖြစ်ပါတယ်။
ပြန်ကြည့်မယ်ဆိုရင်
newFixedThreadPool က LinkedBlockingQueue
newCachedThreadPool က SynchronousQueue
newSingleThreadExecutor က LinkedBlockingQueue
ဆိုတဲ့ Queue Data Structures တွေကို သုံးသွားတာကို မြင်တွေ့နိုင်မှာဖြစ်ပါတယ်။
This content originally appeared on DEV Community and was authored by Zaw Htut Win

Zaw Htut Win | Sciencx (2025-07-14T01:42:00+00:00) အခန်း(၅) ThreadPoolExecutor နဲ့ တွဲသုံးတဲ့ Datastructure များ(Data Structures in Action). Retrieved from https://www.scien.cx/2025/07/14/%e1%80%a1%e1%80%81%e1%80%94%e1%80%ba%e1%80%b8%e1%81%85-threadpoolexecutor-%e1%80%94%e1%80%b2%e1%80%b7-%e1%80%90%e1%80%bd%e1%80%b2%e1%80%9e%e1%80%af%e1%80%b6%e1%80%b8%e1%80%90%e1%80%b2%e1%80%b7-datas/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.