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

Summary and arrangement of Java multithreading model in actual project

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Share the multithreaded model used in recent projects.

Need to be implemented: automatically deploy ES clusters and provide ES services according to the forms filled out by tenants.

Basic ideas:

Is to divide a transaction life cycle into different phases, each of which is executed by a thread.

At present, it is mainly divided into four stages: event monitoring phase, event submission phase, executor phase, and state verification phase.

The flow chart is as follows:

Thread classification:

A, listening thread

B, worker thread

C, status check thread

D, executor thread

A brief introduction to the schematic:

1. AcceptorThread thread: listen on the operation pair list, throw the newly generated event record into the event classifier, and add a record to the memory container at the same time.

2. Event classifier: create different worker threads according to the type of event

3. Worker thread: the worker thread works specifically, such as calling the create interface of marathon, deleting the interface, stopping the interface, etc.

4. Actuator:

A, constantly listening to the execution container, if there is a task, to perform, such as stop the node, start the node, restore the node and other operations.

B. update the status of the node table and the status of the node in the in-memory cache container

5. OptStateThread: listens to the in-memory cache container OptMap and generates different verification threads according to the type if a new event occurs

6. verification thread: specifically responsible for the verification; update the status of the cluster according to the result of the verification

Summary:

A. it embodies the ideas of producers and consumers.

B, the event is divided, and each thread is only responsible for its own separate part.

C. learn to split the life cycle of a transaction reasonably.

D. horizontal thinking should be divided into stages and modules.

The code is not very important, mainly to understand this design pattern, design ideas.

In fact, you can draw knowledge from Netty's multithreaded model and apply it to future projects.

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

Servers

Wechat

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

12
Report