# asyncframework
**Repository Path**: yangtao9898/asyncframework
## Basic Information
- **Project Name**: asyncframework
- **Description**: No description available
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2019-09-30
- **Last Updated**: 2025-02-03
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# asyncframework
#### Description
A asynchronous framework.
#### Software Architecture
Software architecture description
#### Installation
1. Clone the project with git and package jar file with IDE.
2. Put the jar file in your project.
#### Instructions
* 连接池的使用方法
* Use of thread pool.
>(1) Get the thread pool instance with ThreadPoolFactory just like this:
>(1) 通过 ThreadPoolFactory 类获得连接池的实例,如下所示:
DefalutThreadPool pool = ThreadPoolFactory.newFixedThreadPool(10); // Fxied number of threads 固定线程数量
DefalutThreadPool pool = ThreadPoolFactory.newCachedThreadPool(); // Auto manager the number of threads 线程数量自动增加
>(2) Start processing tasks with this method.
>(2) 通过如下的方法开始处理任务
DefalutThreadPool.execute(Runnable task);
* 异步框架的使用方法
>(1) 通过 AsyncClass 构建异步类
>> 有如下一个普通 Java 类
class People {
public People(String name) {
}
String getName(String name) {
return name;
}
int getAge(int age) {
return age;
}
String sleepReturn(String str) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return str;
}
void throwException() throws Exception {
throw new Exception("异常");
}
}
>> 通过 AsyncClass 将该类构造为一个异步执行的类
AsyncClass asyncClass = new AsyncClass();
People p = asyncClass.createAsyncExecuteClass(People.class); // p 成了一个异步类
// 异步方法执行完成后的回调,在调用方法前使用
asyncClass.setCallBackForCompleteAsyncCall((future) -> {
if (future.isSucc()) {
System.out.println("getAge执行成功,返回结果是:" + future.getReturnObj());
} else {
System.out.println("getAge执行失败,失败原因是:" + future.getThrowable());
}
});
// 异步类的所有返回值都为空
p.getAge(23);
// 要获得异步类的返回值,通过如下方法,在调用方法后使用
// 此方法会阻塞线程
asyncClass.getFuture().get();
// 此方法不会阻塞线程,如果没有结果,则会返回空
asyncClass.getFuture().getNow();
// 停止所有创建出来的异步类的执行并且关闭线程池
asyncClass.close();
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)