share the multithreaded models used in recent projects.
Need to implement: automatically deploy ES clusters and provide ES services based on forms that are filled out by tenants.
Basic ideas:
is to divide a transaction life cycle into different stages, each of which is executed with threads.
At present, it is divided into four stages: event monitoring stage, event submission stage, actuator stage, State check stage
The flowchart is as follows:
650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/06/f1a9c0dd5b20cc6d6cd3d156f1543930.png "title=" es-001--threading model. png "alt=" F1a9c0dd5b20cc6d6cd3d156f1543930.png "/>
Thread Classification:
A. Listening thread
B. Worker threads
C, status Check thread
D, Actuator thread
Schematic Brief Introduction:
1. Acceptorthread thread: Listens to the list of actions, throws the newly generated event record into the event classifier, and adds a record to the memory container at the same time.
2. Event classifier: Create different worker threads depending on the type of event
3. Worker thread: Work thread is working, such as create interface for calling marathon, delete interface, stop interface, etc.
4. Actuator:
A, continuous monitoring of the execution of the container, there are tasks, then go to execute, such as stop nodes, start nodes, restore nodes and other operations.
B, update the state of the node table, and the State of the node in the memory cache container
5, Optstatethread: Monitor the memory cache container Optmap, if there are new events occur, depending on the type of the different check threads;
6, check the thread: the specific responsible for the verification, according to the results of the check to update the status of the cluster
Summarize:
A, the embodiment of the producers, consumer thinking
B, the event is divided, the respective threads are responsible for their own separate parts.
C, the life cycle of the transaction, we must learn to carry out reasonable split
D, to lateral thinking, phased, sub-module division
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.
This article is from the "Xej Distributed Studio" blog, so be sure to keep this source http://xingej.blog.51cto.com/7912529/1979357
Summary and collation of Java Multithreading model in actual project