Mercurial > hg > Database > Alice
diff src/alice/codesegment/CodeSegmentManager.java @ 21:145667a554ad
run CodeSegment with ThreadPoolExecutor
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Jan 2012 19:02:01 +0900 |
parents | 0bb03861b5cd |
children | 3155337e754e |
line wrap: on
line diff
--- a/src/alice/codesegment/CodeSegmentManager.java Sun Jan 15 18:44:25 2012 +0900 +++ b/src/alice/codesegment/CodeSegmentManager.java Sun Jan 15 19:02:01 2012 +0900 @@ -1,10 +1,17 @@ package alice.codesegment; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; public class CodeSegmentManager { private static CodeSegmentManager instance = new CodeSegmentManager(); public LinkedBlockingQueue<CodeSegment> readyQueue = new LinkedBlockingQueue<CodeSegment>(); + ThreadPoolExecutor codeSegmentExecutor = new ThreadPoolExecutor(1, + Runtime.getRuntime().availableProcessors(), + Integer.MAX_VALUE, + TimeUnit.SECONDS, + new LinkedBlockingQueue<Runnable>()); private CodeSegmentManager() { Runnable prepareThread = new Runnable() { @@ -14,7 +21,7 @@ while (true) { try { CodeSegment cs = readyQueue.take(); - cs.run(); + codeSegmentExecutor.execute(cs); } catch (InterruptedException e) { e.printStackTrace(); }