Mercurial > hg > Database > Alice
changeset 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 | 2ca2d961a8d2 |
files | src/alice/codesegment/CodeSegment.java src/alice/codesegment/CodeSegmentManager.java |
diffstat | 2 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/codesegment/CodeSegment.java Sun Jan 15 18:44:25 2012 +0900 +++ b/src/alice/codesegment/CodeSegment.java Sun Jan 15 19:02:01 2012 +0900 @@ -2,7 +2,7 @@ import alice.codesegment.InputDataSegment; -public abstract class CodeSegment { +public abstract class CodeSegment implements Runnable { public InputDataSegment ids = new InputDataSegment(this); public OutputDataSegment ods = new OutputDataSegment(); @@ -10,7 +10,5 @@ public void execute() { ids.receive(); } - - public abstract void run(); }
--- 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(); }