Mercurial > hg > Database > Christie
changeset 208:ef5aad739292
update priority
author | akahori |
---|---|
date | Sun, 10 Mar 2019 16:25:52 +0900 |
parents | dd3c0ba6a0a6 |
children | 2ecb3a93b8ae |
files | src/main/java/christie/codegear/CodeGear.java src/main/java/christie/codegear/CodeGearManager.java src/main/java/christie/codegear/PriorityThreadPoolExecutors.java src/main/java/christie/codegear/StartCodeGear.java src/main/java/christie/test/PriorityTest/StartPriorityTest.java |
diffstat | 5 files changed, 18 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/christie/codegear/CodeGear.java Sat Mar 09 21:53:37 2019 +0900 +++ b/src/main/java/christie/codegear/CodeGear.java Sun Mar 10 16:25:52 2019 +0900 @@ -26,6 +26,10 @@ protected abstract void run(CodeGearManager cgm); + public void setup(CodeGearManager cgm){ + setup(cgm, Thread.NORM_PRIORITY); + } + public void setup(CodeGearManager cgm, int priority){ this.cgm = cgm; this.cge = new CodeGearExecutor(this, this.cgm, priority);
--- a/src/main/java/christie/codegear/CodeGearManager.java Sat Mar 09 21:53:37 2019 +0900 +++ b/src/main/java/christie/codegear/CodeGearManager.java Sun Mar 10 16:25:52 2019 +0900 @@ -55,7 +55,7 @@ } public void submit(CodeGear cg){ - threadPoolExecutor.execute(PriorityThreadPoolExecutors.PriorityRunnable.of(cg.getCge(), cg.getCge().getPriority())); + threadPoolExecutor.execute(cg.getCge()); } public void setup(CodeGear cg){
--- a/src/main/java/christie/codegear/PriorityThreadPoolExecutors.java Sat Mar 09 21:53:37 2019 +0900 +++ b/src/main/java/christie/codegear/PriorityThreadPoolExecutors.java Sun Mar 10 16:25:52 2019 +0900 @@ -32,24 +32,19 @@ } private Runnable newComparableRunnableFor(Runnable runnable) { - return new ComparableRunnable(ensurePriorityRunnable(runnable)); + return new ComparableRunnable((CodeGearExecutor) runnable); } @Override protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) { - return new ComparableFutureTask<>(ensurePriorityRunnable(runnable), value); - } - - private PriorityRunnable ensurePriorityRunnable(Runnable runnable) { - return (runnable instanceof PriorityRunnable) ? (PriorityRunnable) runnable - : PriorityRunnable.of(runnable, DEFAULT_PRIORITY); + return new ComparableFutureTask<>((CodeGearExecutor)runnable, value); } private class ComparableFutureTask<T> extends FutureTask<T> implements ComparableTask { private Long sequentialOrder = instanceCounter.getAndIncrement(); - private HasPriority hasPriority; + private CodeGearExecutor hasPriority; - public ComparableFutureTask(PriorityRunnable priorityRunnable, T result) { + public ComparableFutureTask(CodeGearExecutor priorityRunnable, T result) { super(priorityRunnable, result); this.hasPriority = priorityRunnable; } @@ -67,12 +62,10 @@ private static class ComparableRunnable implements Runnable, ComparableTask { private Long instanceCount = instanceCounter.getAndIncrement(); - private HasPriority hasPriority; - private Runnable runnable; + private CodeGearExecutor runnable; - public ComparableRunnable(PriorityRunnable priorityRunnable) { + public ComparableRunnable(CodeGearExecutor priorityRunnable) { this.runnable = priorityRunnable; - this.hasPriority = priorityRunnable; } @Override @@ -82,7 +75,7 @@ @Override public int getPriority() { - return hasPriority.getPriority(); + return runnable.getPriority(); } @Override @@ -108,26 +101,4 @@ } - public interface HasPriority{ - int getPriority(); - } - - - public interface PriorityRunnable extends Runnable, HasPriority{ - - public static PriorityRunnable of(Runnable runnable, int priority) { - return new PriorityRunnable() { - @Override - public void run() { - runnable.run(); - } - - @Override - public int getPriority() { - return priority; - } - }; - } - } - } \ No newline at end of file
--- a/src/main/java/christie/codegear/StartCodeGear.java Sat Mar 09 21:53:37 2019 +0900 +++ b/src/main/java/christie/codegear/StartCodeGear.java Sun Mar 10 16:25:52 2019 +0900 @@ -7,17 +7,19 @@ public abstract class StartCodeGear extends CodeGear{ static ConcurrentHashMap<Integer, CodeGearManager> cgmList = new ConcurrentHashMap<>(); - //static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>(); - /*static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads + /*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);*/ - static ThreadPoolExecutor threadPoolExecutor = PriorityThreadPoolExecutors.createThreadPool(Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE); + static ThreadPoolExecutor threadPoolExecutor = PriorityThreadPoolExecutors.createThreadPool(Runtime.getRuntime().availableProcessors(), + Integer.MAX_VALUE); static int cgmCount = 1; public StartCodeGear(CodeGearManager cgm){ cgm.setup(this); + } public static CodeGearManager createCGM(int localPort){ @@ -33,5 +35,4 @@ @Override protected void run(CodeGearManager cgm) {} - }
--- a/src/main/java/christie/test/PriorityTest/StartPriorityTest.java Sat Mar 09 21:53:37 2019 +0900 +++ b/src/main/java/christie/test/PriorityTest/StartPriorityTest.java Sun Mar 10 16:25:52 2019 +0900 @@ -18,7 +18,7 @@ for(int i = 0; i < max; i ++){ cgm.setup(new PriorityTestCodeGear("A" + String.valueOf(i), 200),0); //Defaults to priority=0 } - + //Priority=1 for(int i = 0; i < max; i ++){ cgm.setup(new PriorityTestCodeGear("B" + String.valueOf(i), 200),1); //Defaults to priority=0 }