scheduler.java
来自「一个很好的微工作流内核」· Java 代码 · 共 49 行
JAVA
49 行
/* * * Copyright (c) 2002 Dragos Manolescu (dam@micro-workflow.com) * * See the LICENSE file for licensing information. */package com.microworkflow.execution;import java.util.logging.Logger;import EDU.oswego.cs.dl.util.concurrent.*;public class Scheduler { public static final int THREADS=3; public static final int THREAD_TIMEOUT=3000; protected PooledExecutor threadPool; Logger logger=Logger.getLogger("com.microworkflow.execution.Scheduler"); public Scheduler() { initialize(); } protected void initialize() { threadPool=new PooledExecutor(new LinkedQueue()); threadPool.setKeepAliveTime(THREAD_TIMEOUT); threadPool.createThreads(THREADS); } public void shutdown() { threadPool.shutdownNow(); } public void scheduleCommand(Closure command) { try { threadPool.execute(new CommandWrapper(command)); } catch (Exception e) { } } public void waitForCompletion() { threadPool.shutdownAfterProcessingCurrentlyQueuedTasks(); logger.info("Waiting on queued threads to complete"); try { threadPool.awaitTerminationAfterShutdown(); } catch (IllegalStateException e) { logger.severe("Invalid pool state"); } catch (InterruptedException e) { logger.info("Thread interrupted"); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?