> For the complete documentation index, see [llms.txt](https://cxz.gitbook.io/spring-cloud-date-flow/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cxz.gitbook.io/spring-cloud-date-flow/tasks/jian-jie.md).

# 简介

Task Applications 的生命周期很短，这意味着它会自定停止运行，可以按需执行或计划执行。实际使用中，可能是抓取web页面数据并写入数据库。  [Spring Cloud Task](https://cloud.spring.io/spring-cloud-task/) 框架基于 Spring Boot，可以记录Applications 的结束退出状态以及 生命周期中的事件管理，比如它何时启动、何时结束以及退出。[TaskExecution](https://docs.spring.io/spring-cloud-task/docs/2.0.0.RELEASE/reference/htmlsingle/#features-task-execution-details) 文档描述了哪些信息会存储在数据库中。Spring Cloud Task Applications 中代码执行的入口点通常是Boot的CommandLineRunner 接口的实现，如 [example](https://docs.spring.io/spring-cloud-task/docs/2.0.0.RELEASE/reference/htmlsingle/#getting-started-writing-the-code) 所示。

对于编写生命周期短的 Applications 的Spring开发人员来说，可能会想到使用 Spring Batch 项目。Spring Batch提供了比Spring Cloud Task更丰富的功能，在处理大数据时推荐使用它。用例可能是读取许多CSV文件，转换每行数据，并将每个转换后的行数据写入数据库。Spring Batch 提供了自己的数据库模式，其中 Spring Batch 的数据库中涵盖了详细的作业执行的 [set of information](https://docs.spring.io/spring-batch/4.1.x/reference/html/schema-appendix.html#metaDataSchema)。Spring Cloud Task 与 Spring Batch 集成，这样，如果Spring Cloud Task Applications 定义了Spring Batch `Job`，就会创建Spring Cloud Task和Spring Cloud Batch 执行表中的关联。

在本地计算机上运行 Data Flow 时，Tasks 将在单独的JVM中启动。在Cloud Foundry上运行时，使用[ ](https://docs.cloudfoundry.org/devguide/using-tasks.html)[Cloud Foundry’s Task](https://docs.cloudfoundry.org/devguide/using-tasks.html) 功能启动，在Kubernetes上运行时，使用`Pod`或`Job`资源启动任务。
