当前位置:网站首页>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)
- In 2021, the global carbon graphite brush revenue is about US $2366million, and it is expected to reach US $2701.8 million in 2028
- Private dry goods sharing: how to implement platform in Enterprise Architecture
- 今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
- Interview shock 60: what will cause MySQL index invalidation?
- MIT6.031 软件构造 Reading7阅读笔记Designing Specifications(设计规范)
- log4j.properties的配置详解
- Hibernate operation Oracle database primary key auto increment
- How to participate in openharmony code contribution
- 面试突击60:什么情况会导致 MySQL 索引失效?
猜你喜欢
随机推荐
Two usages of enumeration classes
Private dry goods sharing: how to implement platform in Enterprise Architecture
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)
Dynamic programming [4] (counting class DP) example: integer partition
Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022
数学知识——博弈论(巴什博奕、尼姆博奕、威佐夫博奕)思路及例题
Use of message queues
ACL 2022 | 中科院提出TAMT:TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络
log4j. Detailed configuration of properties
Raspberry pie 3b+ learning
全球最强截图软件 Snipaste
Master formula
log4j.properties的配置详解
pull request
How histrix works
Deep understanding of happens before principle
How to find the movie and TV clips with the same lines? These 8 movies search for artifact, and find the corresponding segment in one line
Mit6.031 software construction7 reading notesdesigning specifications
Interviewer: with the for loop, why do you need foreach?
mybaitis生成器详解









![Dynamic programming [4] (counting class DP) example: integer partition](/img/06/4b3863bbb85582348c6f4ea7c5511e.png)