Mercurial > hg > Database > Alice
view 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 source
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() { @Override public void run() { while (true) { try { CodeSegment cs = readyQueue.take(); codeSegmentExecutor.execute(cs); } catch (InterruptedException e) { e.printStackTrace(); } } } }; new Thread(prepareThread, "CodeSegmentManager").start(); } public void create(CodeSegment cs) { } public static CodeSegmentManager get() { return instance; } }