{"id":13635509,"url":"https://github.com/houbb/async","last_synced_at":"2025-04-10T18:31:27.069Z","repository":{"id":57720074,"uuid":"173562900","full_name":"houbb/async","owner":"houbb","description":"🦄The async tool for java.(Java 多线程异步并行框架，基于 java 字节码，支持注解。)","archived":false,"fork":false,"pushed_at":"2022-11-30T04:49:32.000Z","size":70,"stargazers_count":29,"open_issues_count":0,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T02:51:34.999Z","etag":null,"topics":["async","async-spring","asynchronous","parallel","parallel-programming"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/houbb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-03T10:56:02.000Z","updated_at":"2025-01-24T11:31:04.000Z","dependencies_parsed_at":"2023-01-23T16:00:26.140Z","dependency_job_id":null,"html_url":"https://github.com/houbb/async","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Fasync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Fasync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Fasync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Fasync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/houbb","download_url":"https://codeload.github.com/houbb/async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248271688,"owners_count":21075800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-spring","asynchronous","parallel","parallel-programming"],"created_at":"2024-08-02T00:00:46.497Z","updated_at":"2025-04-10T18:31:26.052Z","avatar_url":"https://github.com/houbb.png","language":"Java","funding_links":[],"categories":["Java","测试"],"sub_categories":["客户端"],"readme":"# 项目简介\n\n基于注解的 java 异步处理框架。\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.houbb/async/badge.svg)](http://mvnrepository.com/artifact/com.github.houbb/async)\n[![Build Status](https://www.travis-ci.org/houbb/async.svg?branch=master)](https://www.travis-ci.org/houbb/async?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/houbb/async/badge.svg?branch=master)](https://coveralls.io/github/houbb/async?branch=master)\n\n## 设计目的\n\n并行执行可以大幅度提升程序的运行速度，有效利用 CPU 资源。\n\n但是单独为每次方法都使用线程池手写，显然不够优雅，复用性也很差。\n\n## 特性\n\n- 支持接口类的动态代理异步\n\n- 支持非接口类的 CGLIB 代理异步\n\n# 快速入门\n\n具体测试代码，参见 async-test 模块。 \n\n## 需要\n\n- jdk1.7+\n\n- maven 3.x+\n\n## 引入 maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.houbb\u003c/groupId\u003e\n    \u003cartifactId\u003easync-core\u003c/artifactId\u003e\n    \u003cversion\u003e0.0.3\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## 定义测试对象\n\n- 定义接口\n\n当前版本没有引入 CGLIB 等字节码包，需要实现接口才能异步并行。\n\n如果不实现接口，则不实现异步并行。\n\n下个版本会添加 CGLIB，则不用实现接口。\n\n```java\nimport com.github.houbb.async.core.model.async.AsyncResult;\n\n/**\n * 用户服务接口\n * @author binbin.hou\n * date 2019/3/7\n * @since 0.0.1\n */\npublic interface UserService {\n\n    /**\n     * 查询用户信息\n     * @param id 主键\n     * @return 结果\n     */\n    AsyncResult\u003cString\u003e queryUser(final String id);\n\n}\n```\n\n- 定义测试实现类\n\n```java\npublic class UserServiceImpl implements UserService {\n\n    @Override\n    public AsyncResult\u003cString\u003e queryUser(String id) {\n        System.out.println(\"开始根据用户id 查询用户信息 \" + id);\n        try {\n            // 沉睡模拟处理耗时\n            TimeUnit.SECONDS.sleep(3);\n        } catch (InterruptedException e) {\n            e.printStackTrace();\n        }\n        final String result = id + \"-result\";\n        System.out.println(\"结束根据用户id 查询用户信息 \" + result);\n\n        AsyncResult\u003cString\u003e asyncResult = new AsyncResult\u003c\u003e();\n        asyncResult.setValue(result);\n        return asyncResult;\n    }\n\n}\n```\n\n## 测试\n\n### 不使用代理\n\n常规使用方式\n\n```java\n/**\n * 默认不使用代理\n */\n@Test\npublic void queryUserTest() {\n    long start = System.currentTimeMillis();\n    UserService userService = new UserServiceImpl();\n    AsyncResult\u003cString\u003e result = userService.queryUser(\"123\");\n    AsyncResult\u003cString\u003e result2 = userService.queryUser(\"1234\");\n\n    System.out.println(\"查询结果\" + result.getResult());\n    System.out.println(\"查询结果\" + result2.getResult());\n    long end = System.currentTimeMillis();\n    System.out.println(\"共计耗时: \" + (end-start));\n}\n```\n\n- 日志信息\n\n```\n开始根据用户id 查询用户信息 123\n结束根据用户id 查询用户信息 123-result\n开始根据用户id 查询用户信息 1234\n结束根据用户id 查询用户信息 1234-result\n查询结果123-result\n查询结果1234-result\n共计耗时: 6009\n```\n\n### 使用代理\n\n```java\n/**\n * 使用动态代理\n */\n@Test\npublic void queryUserDynamicProxyTest() {\n    long start = System.currentTimeMillis();\n    UserService userService = new UserServiceImpl();\n    UserService userServiceProxy = (UserService) AsyncProxy.getProxy(userService);\n    AsyncResult\u003cString\u003e result = userServiceProxy.queryUser(\"123\");\n    AsyncResult\u003cString\u003e result2 = userServiceProxy.queryUser(\"1234\");\n\n    System.out.println(\"查询结果\" + result.getResult());\n    System.out.println(\"查询结果\" + result2.getResult());\n    long end = System.currentTimeMillis();\n    System.out.println(\"共计耗时: \" + (end-start));\n}\n```\n\n- 日志信息\n\n```\n开始根据用户id 查询用户信息 123\n开始根据用户id 查询用户信息 1234\n结束根据用户id 查询用户信息 123-result\n结束根据用户id 查询用户信息 1234-result\n查询结果123-result\n查询结果1234-result\n共计耗时: 3009\n```\n\n同样的功能实现，节约了将近一半的时间。\n\n# 拓展阅读\n\n[Async-01-项目模块说明](doc/blog/async-01-项目模块介绍.md)\n\n[Async-02-CGLIB代理.md](doc/blog/async-02-CGLIB代理.md)\n\n[Async-03-Spring-整合.md](doc/blog/async-03-spring-整合.md)\n\n# 后期 Road-MAP\n\n- [ ] 开启可以指定为 sync 或者 async 的方式执行。\n\n- [ ] 对于返回值的优化，返回值可以是任何类型。\n\n- [ ] 添加 spring-boot-starter 特性\n\n# 中间件等工具开源矩阵\n\n[heaven: 收集开发中常用的工具类](https://github.com/houbb/heaven)\n\n[rpc: 基于 netty4 实现的远程调用工具](https://github.com/houbb/rpc)\n\n[mq: 简易版 mq 实现](https://github.com/houbb/mq)\n\n[ioc: 模拟简易版 spring ioc](https://github.com/houbb/ioc)\n\n[mybatis: 简易版 mybatis](https://github.com/houbb/mybatis)\n\n[cache: 渐进式 redis 缓存](https://github.com/houbb/cache)\n\n[jdbc-pool: 数据库连接池实现](https://github.com/houbb/jdbc-pool)\n\n[sandglass: 任务调度时间工具框架](https://github.com/houbb/sandglass)\n\n[sisyphus: 支持注解的重试框架](https://github.com/houbb/sisyphus)\n\n[resubmit: 防止重复提交框架，支持注解](https://github.com/houbb/resubmit)\n\n[auto-log: 日志自动输出](https://github.com/houbb/auto-log)\n\n[async: 多线程异步并行框架](https://github.com/houbb/async)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoubb%2Fasync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoubb%2Fasync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoubb%2Fasync/lists"}