view src/main/java/christie/codegear/StartCodeGear.java @ 7:21372a589bd3

add CodeGearExecutor
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Wed, 27 Dec 2017 18:42:46 +0900
parents 3dcfe63d6394
children efaa7ad906b3
line wrap: on
line source

package christie.codegear;

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

public abstract class StartCodeGear extends CodeGear{
    static ConcurrentHashMap<String, CodeGearManager> cgms = new ConcurrentHashMap<>();
    static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>();
    static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads
            Runtime.getRuntime().availableProcessors(),
            Integer.MAX_VALUE, // keepAliveTime
            TimeUnit.SECONDS,
            taskQueue);


    public static CodeGearManager createCGM(String name){
        CodeGearManager cgm = new CodeGearManager(threadPoolExecutor);
        cgms.put(name, cgm);
        return cgm;
    }

    public CodeGearManager getCGM(String name){
        return cgms.get(name);
    }


}