From e6483c4b2673ed6c4240ca3aba0fefb108c3e100 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Fri, 22 Feb 2019 15:27:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EClass=E7=9A=84=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=BC=93=E5=AD=98=EF=BC=8C=E8=A7=A3=E5=86=B3=E9=A2=91?= =?UTF-8?q?=E7=B9=81=E5=8A=A0=E8=BD=BDClass=E4=BC=9A=E4=BD=BFjvm=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=8C=BA=E7=A9=BA=E9=97=B4=E4=B8=8D=E8=B6=B3?= =?UTF-8?q?=E5=AF=BC=E8=87=B4OOM=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 3 +- .../job/core/biz/impl/ExecutorBizImpl.java | 2 +- .../com/xxl/job/core/glue/GlueFactory.java | 48 ++++++++----------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 521e6725..fe2512c9 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1425,7 +1425,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 11、执行器回调日志落盘方案复用RPC序列化方案,并移除Jackson依赖; - 12、任务支持更换绑定执行器,方便任务分组转移和管理; - 13、执行器热部署时JobHandler重新初始化,修复由此导致的 "jobhandler naming conflicts." 问题; -- 14、[迭代中]任务线程隔离: +- 14、新增Class的加载缓存,解决频繁加载Class会使jvm的方法区空间不足导致OOM的问题; +- 15、[迭代中]任务线程隔离: - 执行器测异步响应,不存在阻塞不需要隔离; - 调度中心共用单一调度线程池,可能导致调度阻塞需要线程隔离;调度线程池拆分为Fast/Slow两个,针对调度较慢的执行器地址请求,降级使用Slow线程池;考虑是否可以任务级隔离线程池; diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java b/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java index 36b12f2f..e5b90b7a 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java @@ -113,7 +113,7 @@ public class ExecutorBizImpl implements ExecutorBiz { // valid handler if (jobHandler == null) { try { - IJobHandler originJobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getJobId(), triggerParam.getGlueSource()); + IJobHandler originJobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getGlueSource()); jobHandler = new GlueJobHandler(originJobHandler, triggerParam.getGlueUpdatetime()); } catch (Exception e) { logger.error(e.getMessage(), e); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java index d6104026..4b457492 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java @@ -33,9 +33,7 @@ public class GlueFactory { * groovy class loader */ private GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); - - private static final ConcurrentHashMap> CLASS_CACHE = new ConcurrentHashMap<>(); - private static final ConcurrentHashMap JOBID_MD5KEY_CACHE = new ConcurrentHashMap<>(); + private ConcurrentHashMap> CLASS_CACHE = new ConcurrentHashMap<>(); /** * load new instance, prototype @@ -44,9 +42,9 @@ public class GlueFactory { * @return * @throws Exception */ - public IJobHandler loadNewInstance(long jobId, String codeSource) throws Exception{ + public IJobHandler loadNewInstance(String codeSource) throws Exception{ if (codeSource!=null && codeSource.trim().length()>0) { - Class clazz = getCodeSourceClass(jobId, codeSource); + Class clazz = getCodeSourceClass(codeSource); if (clazz != null) { Object instance = clazz.newInstance(); if (instance!=null) { @@ -62,38 +60,30 @@ public class GlueFactory { } throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null"); } - - /** - * inject service of bean field - * - * @param instance - */ - public void injectService(Object instance) { - // do something - } - - private Class getCodeSourceClass(long jobId, String codeSource){ + private Class getCodeSourceClass(String codeSource){ try { - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] md5 = md.digest(codeSource.getBytes()); - BigInteger no = new BigInteger(1, md5); - String md5Str = no.toString(16); + // md5 + byte[] md5 = MessageDigest.getInstance("MD5").digest(codeSource.getBytes()); + String md5Str = new BigInteger(1, md5).toString(16); + Class clazz = CLASS_CACHE.get(md5Str); if(clazz == null){ clazz = groovyClassLoader.parseClass(codeSource); - Class preClazz = CLASS_CACHE.putIfAbsent(md5Str, clazz); - - // 如果代碼有變化則刪除之前class緩存 - if(preClazz == null){ - String preMd5 = JOBID_MD5KEY_CACHE.put(jobId, md5Str); - if(preMd5 != null){ - CLASS_CACHE.remove(preMd5); - } - } + CLASS_CACHE.putIfAbsent(md5Str, clazz); } return clazz; } catch (Exception e) { return groovyClassLoader.parseClass(codeSource); } } + + /** + * inject service of bean field + * + * @param instance + */ + public void injectService(Object instance) { + // do something + } + }