Skip to content

Commit 0f994a6

Browse files
committed
执行器任务Bean扫描逻辑优化,完善懒加载Bean检测及过滤机制;
1 parent b5c5bf7 commit 0f994a6

File tree

2 files changed

+31
-42
lines changed

2 files changed

+31
-42
lines changed

doc/XXL-JOB官方文档.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,10 +2580,11 @@ public void execute() {
25802580
- 8、【修复】调度预读任务数量调整,改为调度线程池大小x10,降低事务颗粒度,提升性能及稳定性;
25812581
- 9、【优化】调度不重不漏逻辑优化:调度时间轮单刻度数据去重,避免极端情况下任务重复执行;时间轮转动时校验临近刻度,避免极端情况下遗漏刻度;
25822582
- 10、【重构】调度过期策略、调度类型策略逻辑重构,代码组件化拆分并完善日志,提升健壮性及可维护性;
2583-
- 11、【ING】UI框架重构升级,提升交互体验;
2584-
- 12、【ING】调整资源加载逻辑,移除不必要的拦截器逻辑,提升页面加载效率;
2585-
- 13、【ING】规范API交互协议,通用响应结构体调整为Response;
2586-
- 14、【ING】Http通讯组件升级,基于接口代理方式重构;
2583+
- 11、【优化】执行器任务Bean扫描逻辑优化,完善懒加载Bean检测及过滤机制;
2584+
- 12、【ING】UI框架重构升级,提升交互体验;
2585+
- 13、【ING】调整资源加载逻辑,移除不必要的拦截器逻辑,提升页面加载效率;
2586+
- 14、【ING】规范API交互协议,通用响应结构体调整为Response;
2587+
- 15、【ING】Http通讯组件升级,基于接口代理方式重构;
25872588
25882589
25892590
### TODO LIST

xxl-job-core/src/main/java/com/xxl/job/core/executor/impl/XxlJobSpringExecutor.java

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import org.springframework.beans.BeansException;
99
import org.springframework.beans.factory.DisposableBean;
1010
import org.springframework.beans.factory.SmartInitializingSingleton;
11+
import org.springframework.beans.factory.config.BeanDefinition;
1112
import org.springframework.context.ApplicationContext;
1213
import org.springframework.context.ApplicationContextAware;
13-
import org.springframework.context.annotation.Lazy;
14+
import org.springframework.context.support.GenericApplicationContext;
1415
import org.springframework.core.MethodIntrospector;
1516
import org.springframework.core.annotation.AnnotatedElementUtils;
1617

@@ -33,9 +34,6 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
3334
@Override
3435
public void afterSingletonsInstantiated() {
3536

36-
// init JobHandler Repository
37-
/*initJobHandlerRepository(applicationContext);*/
38-
3937
// init JobHandler Repository (for method)
4038
initJobHandlerMethodRepository(applicationContext);
4139

@@ -56,29 +54,11 @@ public void destroy() {
5654
super.destroy();
5755
}
5856

59-
60-
/*private void initJobHandlerRepository(ApplicationContext applicationContext) {
61-
if (applicationContext == null) {
62-
return;
63-
}
64-
65-
// init job handler action
66-
Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class);
67-
68-
if (serviceBeanMap != null && serviceBeanMap.size() > 0) {
69-
for (Object serviceBean : serviceBeanMap.values()) {
70-
if (serviceBean instanceof IJobHandler) {
71-
String name = serviceBean.getClass().getAnnotation(JobHandler.class).value();
72-
IJobHandler handler = (IJobHandler) serviceBean;
73-
if (loadJobHandler(name) != null) {
74-
throw new RuntimeException("xxl-job jobhandler[" + name + "] naming conflicts.");
75-
}
76-
registJobHandler(name, handler);
77-
}
78-
}
79-
}
80-
}*/
81-
57+
/**
58+
* init job handler from method
59+
*
60+
* @param applicationContext applicationContext
61+
*/
8262
private void initJobHandlerMethodRepository(ApplicationContext applicationContext) {
8363
if (applicationContext == null) {
8464
return;
@@ -87,12 +67,28 @@ private void initJobHandlerMethodRepository(ApplicationContext applicationContex
8767
String[] beanDefinitionNames = applicationContext.getBeanNamesForType(Object.class, false, false); // allowEagerInit=false, avoid early initialization
8868
for (String beanDefinitionName : beanDefinitionNames) {
8969

90-
// filter system bean
70+
// skip system bean
9171
if (isSystemBean(beanDefinitionName)) {
9272
continue;
9373
}
9474

95-
// get bean
75+
// skip lazy bean
76+
if (applicationContext instanceof GenericApplicationContext genericApplicationContext) {
77+
if (!genericApplicationContext.containsBeanDefinition(beanDefinitionName)) {
78+
continue;
79+
}
80+
// valid lazy bean
81+
BeanDefinition beanDefinition = genericApplicationContext.getBeanDefinition(beanDefinitionName);
82+
if (beanDefinition.isLazyInit()) {
83+
logger.debug("xxl-job bean-definition scan, skip lazy-init bean:{}", beanDefinitionName);
84+
continue;
85+
}
86+
}
87+
88+
// load bean
89+
Object bean = applicationContext.getBean(beanDefinitionName);
90+
/*
91+
skip lazy bean2
9692
Object bean = null;
9793
Lazy onBean = applicationContext.findAnnotationOnBean(beanDefinitionName, Lazy.class);
9894
if (onBean!=null){
@@ -101,6 +97,7 @@ private void initJobHandlerMethodRepository(ApplicationContext applicationContex
10197
}else {
10298
bean = applicationContext.getBean(beanDefinitionName);
10399
}
100+
*/
104101

105102
// filter method
106103
Map<Method, XxlJob> annotatedMethods = null; // referred to :org.springframework.context.event.EventListenerMethodProcessor.processBean
@@ -149,13 +146,4 @@ public static ApplicationContext getApplicationContext() {
149146
return applicationContext;
150147
}
151148

152-
/*
153-
BeanDefinitionRegistryPostProcessor
154-
registry.getBeanDefine()
155-
@Override
156-
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
157-
this.registry = registry;
158-
}
159-
* */
160-
161149
}

0 commit comments

Comments
 (0)