Java 异步处理框架:ParSeq
yn6e
9年前
ParSeq 是一个简化 Java 编写异步处理代码的框架,优点:
-
异步操作的并行处理
-
顺序执行非堵塞计算
-
通过任务组合实现代码的重用
-
简单的错误传播和恢复
-
执行跟踪和可视化
示例代码:
import com.linkedin.parseq.Engine; import com.linkedin.parseq.EngineBuilder; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; // ... final int numCores = Runtime.getRuntime().availableProcessors(); final ExecutorService taskScheduler = Executors.newFixedThreadPool(numCores + 1); final ScheduledExecutorService timerScheduler = Executors.newSingleThreadScheduledExecutor(); final Engine engine = new EngineBuilder() .setTaskExecutor(taskScheduler) .setTimerScheduler(timerScheduler) .build(); engine.shutdown(); engine.awaitTermination(1, TimeUnit.SECONDS); taskScheduler.shutdown(); timerScheduler.shutdown();