Skip to content

Commit

Permalink
执行器注册线程优化,线程销毁时主动摘除注册机器;
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxueli committed Aug 26, 2017
1 parent 0b4849b commit 7bc11fc
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/XXL-JOB官方文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 4、执行器手动设置IP时将会绑定Host;
- 5、项目主页搭建,提供中英文文档;
- 6、执行器回调线程优化,线程销毁前批量回调队列中所有数据;
- 7、执行器注册线程优化,线程销毁时主动摘除注册机器;
### TODO LIST
- 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public int registrySave(@Param("registryGroup") String registryGroup,
@Param("registryKey") String registryKey,
@Param("registryValue") String registryValue);

public int registryDelete(@Param("registryGroup") String registGroup,
@Param("registryKey") String registryKey,
@Param("registryValue") String registryValue);

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,10 @@ public ReturnT<String> registry(RegistryParam registryParam) {
return ReturnT.SUCCESS;
}

@Override
public ReturnT<String> registryRemove(RegistryParam registryParam) {
xxlJobRegistryDao.registryDelete(registryParam.getRegistGroup(), registryParam.getRegistryKey(), registryParam.getRegistryValue());
return ReturnT.SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@
VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, NOW())
</insert>

<delete id="registryDelete" >
DELETE FROM XXL_JOB_QRTZ_TRIGGER_REGISTRY
WHERE registry_group = #{registryGroup}
AND registry_key = #{registryKey}
AND registry_value = #{registryValue}
</delete>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public void registryTest() throws Exception {
ReturnT<String> returnT = adminBiz.registry(registryParam);
Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);



// test executor registry remove
registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
returnT = adminBiz.registryRemove(registryParam);
Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);

}

}
8 changes: 8 additions & 0 deletions xxl-job-core/src/main/java/com/xxl/job/core/biz/AdminBiz.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public interface AdminBiz {
*/
public ReturnT<String> registry(RegistryParam registryParam);

/**
* registry remove
*
* @param registryParam
* @return
*/
public ReturnT<String> registryRemove(RegistryParam registryParam);

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void start(final int port, final String ip, final String appName){
registryThread = new Thread(new Runnable() {
@Override
public void run() {

// registry
while (!toStop) {
try {
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
Expand Down Expand Up @@ -77,7 +79,26 @@ public void run() {
}

// registry remove
try {
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
try {
ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
registryResult = ReturnT.SUCCESS;
logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
break;
} else {
logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
}
} catch (Exception e) {
logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
}

}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}

}
});
Expand Down

0 comments on commit 7bc11fc

Please sign in to comment.