view src/alice/codesegment/CodeSegmentManager.java @ 70:f2d4a4686036

delete CodeSegment receive thread
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 21 Feb 2012 20:09:18 +0900
parents d4c7f7b1096b
children a3a2605e16a2
line wrap: on
line source

package alice.codesegment;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class CodeSegmentManager {

	private static CodeSegmentManager instance = new CodeSegmentManager();
	public LinkedBlockingQueue<CodeSegment> readyQueue = new LinkedBlockingQueue<CodeSegment>();
	private ThreadPoolExecutor codeSegmentExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads
												Runtime.getRuntime().availableProcessors(),
												Integer.MAX_VALUE, // keepAliveTime
												TimeUnit.SECONDS,
												new LinkedBlockingQueue<Runnable>());
	private Logger log = Logger.getLogger(CodeSegmentManager.class);

	private boolean debug = false;
	
	public static CodeSegmentManager get() {
		return instance;
	}

	public static void submit(CodeSegment cs) {
		CodeSegmentManager csManager = CodeSegmentManager.get();
		csManager.codeSegmentExecutor.execute(cs);
		if (csManager.debug) {
			csManager.log.debug(cs.getClass().getName());
		}
	}
	
}