Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lzh-1.8-async-spring-boot-starter

一个用于简化Spring Boot异步任务处理的starter组件。它为应用程序提供异步执行能力和线程池管理。

特性

  • 提供可配置的异步任务线程池。
  • 支持自定义线程池参数,如核心线程数、最大线程数、队列大小等。
  • 保持请求上下文在异步执行期间不变。
  • 集成Spring的@EnableAsync注解,简化异步方法调用的配置。

模块结构

  • LzhAsyncTaskConfig: 配置类,启用异步任务支持,并定义线程池Bean。
  • LzhAsyncTaskProperties: 属性配置类,用于从application.propertiesapplication.yml中读取线程池相关配置。
  • LzhThreadPoolTaskExecutor: 自定义的线程池任务执行器,扩展了Spring的ThreadPoolTaskExecutor
  • RequestContextAwareCallable & RequestContextAwareRunnable: 确保异步任务执行时保留请求上下文的封装类。
  • RequestContextAwarePoolExecutor: 结合请求上下文支持的线程池执行器。

安装

  1. 将以下依赖添加到你的pom.xml中:
<dependency>
    <groupId>com.lzh</groupId>
    <artifactId>lzh-1.8-async-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>
  1. 配置异步任务相关参数,例如在application.yml中:
lzh:
  async-task:
    core-pool-size: 5
    max-pool-size: 10
    queue-size: 100
    thread-name-prefix: async-task-
    keep-alive-time: 60

使用

确保你的Spring Boot主类或配置类上标注了@EnableAsync。然后你可以使用@Async注解来标记异步执行的方法。

@Service
public class MyAsyncService {

    @Async
    public void asyncMethod() {
        // 异步执行的逻辑
    }
}

贡献者指南

  • Fork这个仓库。
  • 创建新分支 (git checkout -b feature/your-feature-name)
  • 提交更改 (git commit -am 'Add some feature')
  • 推送分支 (git push origin feature/your-feature-name)
  • 创建新的Pull Request

协议

该项目基于MIT协议发布,请查看仓库中的LICENSE文件以获取更多信息。

联系

如果你有任何问题或建议,请在Gitee上提交Issue或者联系作者。


请根据实际的项目文档和代码更新配置和使用部分的具体细节。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages