当前位置:网站首页>Sorting out XXL job learning
Sorting out XXL job learning
2022-06-27 12:29:00 【Xiaopang Xiaobai】
Actuator flow
Inject... Into the configuration class bean:XxlJobSpringExecutor

XxlJobSpringExecutor Implementation interface SmartInitializingSingleton. In all cases bean After instantiation , Go through all the singletons again bean, Execute the callback method that implements this interface afterSingletonsInstantiated

afterSingletonsInstantiated Method execution
① Get the tag in the class @XxlJob Method of annotation . Put in map in ,key:Method,Vaule:XxlJob Annotation class
②registJobHandler(XxlJobExecutor Medium method .XxlJobExecutor yes XxlJobSpringExecutor Parent class of ).
registJobHandler(xxlJob, bean, executeMethod);
take Method Encapsulated in the MethodJobHandler( It contains the target class , Methods can be called directly to execute ). obtain XxlJob In the annotations value attribute , Get the name of the executed method name.
③ take name As key,MehtodJobHandler As value Injection into jobHandlerRepository Properties of the .
jobHandlerRepository yes XxlJobExecutor Properties of . The type is ConcurrentMap<String, IJobHandler>.GlueFactory.refreshInstance(1); Create a... Based on the input parameters GlueFactory class .
Call the parent class XxlJobExecutor Of start() Method .
①XxlJobFileAppender.initLogPath(logPath);
initialization logPath. Initialize log file . If not specified , Default /data/applogs/xxl-job/jobhandler
②initAdminBizList(adminAddresses, accessToken);
according to adminAddresses,accessToken initialization AdminBize. structure AdminBizClient, This class can execute Admin Callback in service , register , Unregister method . It encapsulates the details of remote calls . Will create the AdminBizeClient Save to XxlJobExecutor Properties of adminBizList in .
private static List adminBizList;
③ JobLogFileCleanThread.getInstance().start(logRetentionDays);
JobLogFileCleanThread Is a singleton class . Yes core Package supply . Its job is to clean up log files . Start a thread , Clean up log files regularly .
④ TriggerCallbackThread.getInstance().start();
TriggerCallbackThread It's also a singleton class . Yes core Package supply . Trigger callback , It creates two threads to execute the polling logic .
triggerCallbackThread( Trigger callback thread ):
private LinkedBlockingQueue callBackQueue = new LinkedBlockingQueue();
From the callback blocking queue through the blocking mode (take Method ) Take out a task in the queue . If it's not empty , Take out all the tasks in the queue and put them into an internal collection , And clear the blocking queue .
doCallback Method performs all tasks in the internal collection . adopt adminBiz agent , call admin Service callback method . The returned results are written to the log . Failed write to failed file .
triggerRetryCallbackThread( Trigger retry callback thread ):
To retry the callback thread is to get the task from the failed file , Re execution .
⑤ initEmbedServer(address, ip, port, appname, accessToken);
Initialize the built-in server . Initialize a EmbedServer object , Calling the start Method :
Initializing a proxy object for an actuator :
executorBiz = new ExecutorBizImpl();
Define a thread , Start this thread :
Thread through netty The initial session flow creates a ServerSocketChannel. Listening on a port , Opening service .
Request processing class EmbedHttpServerHandler.
Sign up for service to admin. Registration passed ExecutorRegistryThread The singleton class executes start Method .start Method to open a thread , If there is no termination , Has been performed .run Method by getting adminBiz Proxy object , Call the object's registry Method , towards Admin Register current executor Method . Sleep 30 second , Carry on . If the actuator is set stop = true, The exit while loop , adopt adminBiz Proxy object , call admin Method of canceling the actuator .ExecutorBizImpl Processing of requests in
When admin And executor Establishing a connection . Get the requested by decoding HttpMethod,rui,requestData,accessToken. Through the thread pool , Perform the requested .
Object responseObj = process(httpMethod, uri, requestData, accessTokenReq);
① Basic verification , check httpMethod,uri,accesstoken.
② according to uri,executorBiz The proxy class implements the method of the formation . There are commonly used heartbeat methods , Operation method , Kill service methods, etc .
jobThread Medium run Method execution :
adopt excutor in xxljob Marked with name, stay xxljobexecutor Class jobHandlerRepository Properties of the , adopt key Get the corresponding value(MehtodJobHandler).
Sign up for a job Threads , Put task jobid(uuid only ),jobHandler. start-up job Threads , Execute requests asynchronously . The main process puts the request into jobThread OfblockQueuein . then jobThread Of run Method takes a task from the blocking queue and executes the following process :
① perform handler Of init Method .
②job One of the threads triggerQueue queue . From the queue poll One triggerParam, If it's not empty ,triggerLogIdSet Removes the current from the collection traiggerParam Of logId Corresponding records .
③ perform handler Of executor Method .
④TriggerCallbackThread Put the encapsulated method execution results into the blocking queue . There are callback thread calls admin The callback method of .
A special case . perform 30 Next time , There are no tasks in the blocking queue . take jobThread from xxlJobExecutor Remove , And call jobThread Of toStop Method , Call the current thread interrupt .
xxljobexecutor The following contents are saved in :
(1)jobHandlerRepository: preservation xxljob In the annotations name And corresponding MethodHandler
(2)adminBizList: preservation Admin Service adminbiz Proxy object
(3)jobThreadRepository: Preservation processing admin Requested jobThread object
Admin Initialization flow
- The configuration class is initialized XxlJobScheduler Class init Method .


- XxlJobScheduler Of init Method

①initI18n
internationalization . Don't study
②JobTriggerPoolHelper.toStart();
Initialize trigger thread pool .JobTriggerPoolHelper Class to initialize two thread pools : An express pool , A slow processing thread pool . When the task timeout is set to exceed 10 seconds , We consider it a slow task , Use the slow trigger thread pool to process , The timeout and timeout are not set to be less than 10s We think it will run quickly and be handled by the fast trigger thread pool .
③JobRegistryHelper.getInstance().start();
Initialize registration , Remove thread pool.Initialize listener thread, And enable the listener thread .
Listener thread ,while The loop executes all the time , Update actuator information .
④JobScheduleHelper.getInstance().start();
The execution thread of the scheduled task . Take the task from the scheduled task , adopt JobTriggerPoolHelper.trigger Triggers the task .JobTriggerPoolHelper The two thread pools will be initialized as mentioned above . In the scheduled task, you call XxlJobTrigger.trigger Triggers the task . Find the corresponding actuator ,processTrigger Method processing task . Get the proxy object of the actuator through the address information of the actuator executorBiz, perform run Method .
边栏推荐
- Daily leetcode force deduction (21~25)
- uni-app 使用escook/request-miniprogram插件发请求说明
- Hibernate operation Oracle database primary key auto increment
- What is the TCP 3-time handshake process?
- Dm8: Dameng database - lock timeout
- uniapp下拉弹层选择框效果demo(整理)
- In 2021, the global enhanced oil production surfactant revenue was about USD 202.3 million, and it is expected to reach USD 297.1 million in 2028
- 树莓派 3b+ 学习
- JMETER连接DM8
- C # WPF realizes undo redo function
猜你喜欢

Mathematical knowledge -- ideas and examples of game theory (bash game, Nim game, wizov game)

dried food! What problems will the intelligent management of retail industry encounter? It is enough to understand this article

nmcli team bridge 基本配置

Comment modifier Node Fichiers dans les modules

xxl-job学习梳理
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)](/img/ce/b58e436e739a96b3ba6d2d33cf8675.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)

nifi从入门到实战(保姆级教程)——身份认证

picocli-入门

今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献

Microservice splitting
随机推荐
threejs的环境光+点光源+平行光源+球面光 以及hepler理解+阴影()
MapReduce原理剖析(深入源码)
$15.8 billion! 2021 the world's top15 most profitable hedge fund giant
如何修改 node_modules 裏的文件
StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior
Topic38——56. Consolidation interval
解开C语言的秘密《关键字》(第六期)
Building crud applications in golang
log4j. Detailed configuration of properties
Shell script learning notes
Go Web 编程入门:验证器
Configuration of YML
Research Report on the overall scale, major producers, major regions, products and application segments of swine vaccine in the global market in 2022
ACL 2022 | 中科院提出TAMT:TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络
行业洞察 | 新零售业态下,品牌电商应如何重塑增长?
MySQL high level statements (I)
In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
Maximum path and problem (cherry picking problem)
alibaba jarslink
Master formula