Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java version of e-commerce spring cloud distributed microservice b2b2c-Spring Cloud Task

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

The goal of Spring Cloud Task is to provide Spring Boot applications with the ability to create short-run microservices.

In Spring Cloud Task, we have the flexibility to run any task dynamically, allocate resources as needed, and retrieve results after the task is completed. Tasks is

Spring Cloud Data Flow in a basic project, understand the springcloud architecture can be added to request: 3536247259, allowing users

Execute almost any Spring Boot application as a short-term task.

Life cycle of Spring Cloud Task

Modern cloud platforms are designed around long-lifecycle services, such as web applications. Once enabled, there will be no application unless you restart the application manually.

The continuous operation of the destination. Although most platforms have ways to push the lifecycle of a service to an end without restarting the application, the processing of each service

The results are difficult to maintain in a reusable way. Spring Cloud Task can execute short-lifecycle applications in the platform environment and record the

As a result, each tasks is integrated through a message notification mechanism. Through this feature, we can make short life cycle applications like long life cycle applications.

Samples make up the micro-service architecture.

The Spring Task Cloud approach is very useful for modern cloud environments, but it also creates new problems in deploying applications. Such as using a scheduler (such as corn)

When executing a Spring Boot application, how can the execution result be monitored after the application is finished?

The approach adopted by Spring Cloud Task is to divide Spring Boot applications into start, end, and running states. For example, a batch task is a

For a clear short life cycle application, Spring Cloud Task monitors all lifecycle events for a given task.

The life cycle is the whole process of running a task task instance, and it is also a process in which Spring Boot applications configured as task are executed (by adding @

EnableTask Annotation configuration).

When task starts running (before an instance of CommandLineRunner or ApplicationRunner and its subclasses is executed) TaskRespository will

Create a task record and mark it as start status. The start event is triggered by the SmartLifecycle#start of the spring framework. The start event is triggered.

The system is ready to execute instances of CommandLineRunner or ApplicationRunner and its subclasses.

The task record is recorded only after the ApplicationContext has been successfully started. If ApplicationContext is not started successfully, then task

The relevant information will not be recorded.

When all the * Runner#run interfaces of the Spring Boot application are called, or when the ApplicationContext fails (by

ApplicationFailedEvent), the execution results of this task in the task repository will be updated.

After the task is completed (the * Runner#run method is executed), ApplicationContext is turned off by default. This feature can be found in the configuration file

Change it by setting the spring.cloud.task.closecontext_enable property to false.

The implementation principle is shown in the following code:

Public class TaskLifecycleListener {. / * automatically calls this method * Utilizes {@ link ApplicationEvent} s to determine the start, end, and failure of a * task after a task-related event occurs. Specifically: * * {@ link ContextRefreshedEvent}-Start of a task * {@ link ApplicationReadyEvent}-Successful end of a task * {@ link ApplicationFailedEvent}-Failure of a task * @ param applicationEvent The application being listened for. * / @ Override public void onApplicationEvent (ApplicationEvent applicationEvent) {if (applicationEvent instanceof ApplicationFailedEvent) {this.applicationFailedEvent = (ApplicationFailedEvent) applicationEvent; doTaskEnd ();} else if (applicationEvent instanceof ExitCodeEvent) {this.exitCodeEvent = (ExitCodeEvent) applicationEvent } else if (applicationEvent instanceof ApplicationReadyEvent) {doTaskEnd ();}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report