Re: [問題] 關於Executor運作原理
: → FrankWOO:二樓大大建議我會去看的 11/22 09:59
: → FrankWOO:三樓大大 我已經看過了 他用ThreadPoolExecutor產生限制 11/22 10:01
: → FrankWOO:Thread數量,但是他怎麼拿取BlockingQueue東西的實作 11/22 10:06
大概長這樣吧
//MyExecutor.java
private BlockingQueue<Runnable> queue = ...;
private ThreadFactory factory = ...;
private int numberOfThreads = ...;
public void startSerivce()
{
for(int i=0; i<numberOfThreads; i++)
{
Thread thread = factory.createThread();
thread.start(new Runnable(){
public void run(){
while(!isCancel)
{
// Take task, block until task is available..
Runnalbe task = queue.take();
task.run();
}
}
});
}
}
public void execute(Runnable task)
{
queue.put(task);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.251.162
※ 編輯: popcorny 來自: 220.135.251.162 (11/22 11:38)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):