【源创会预告】1024 程序员节(的前两天),相约开源中国办公室,我们一起聊 AI!>>>
周飒博客-ZhouSa.com 1: 介绍
BeeTP是stone包下一款小型任务池组件,它支持单次任务,定时任务,聚合任务的处理,整体功能类似JUC包中的线程池。
2: 参考例子
public class HelloTask implements BeeTask { public Object call() { return "Hello World"; } }
public class MyTaskTest { public static void main(String[] args) throws Exception { BeeTaskServiceConfig config = new BeeTaskServiceConfig(); config.setWorkerKeepAliveTime(TimeUnit.SECONDS.toMillis(10)); BeeTaskService service = new BeeTaskService(config); //作为单次任务 BeeTaskHandle handle = service.submit(new HelloTask()); //作为定时任务 service.scheduleAtFixedRate(new HelloTask(), 0, 2, TimeUnit.SECONDS); //打印单次任务结果 System.out.println("Result:" + handle.get()); } }
单次任务,定时任务,聚合任务的接口提交方法使用的均是基于BeeTask的实现。
3: 修改内容
2:修复任务句柄中的取消时的并发性bug
3:在重构的基础上增加树状聚合型任务: BeeTreeTask,源码如下
public interface BeeTreeTask<E> { /** * return pre-split sub tasks * * @return sub tasks of current task */ BeeTreeTask<E>[] getSubTasks(); /** * execute call with handle array of sub tasks * * @param subTaskHandles handle array of sub tasks * @return execution value of method call * @throws Exception occurred in execution */ E call(BeeTaskHandle<E>[] subTaskHandles) throws Exception; }
4: 版本下载
<dependency> <groupId>io.github.chris2018998</groupId> <artifactId>stone</artifactId> <version>1.2.4</version> </dependency>
5: 项目地址
https://gitee.com/Chris2018998/stone
https://github.com/Chris2018998/stone
还没有评论,来说两句吧...