diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java b/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java index 7d3d13c6..3f2dfc81 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java @@ -27,14 +27,19 @@ public class XxlJobContext { // ---------------------- for log ---------------------- /** - * job log timestamp + * log id */ - private final long jobLogTime; - + private final long logId; + + /** + * log timestamp + */ + private final long logDateTime; + /** - * job log filename + * log filename */ - private final String jobLogFileName; + private final String logFileName; // ---------------------- for shard ---------------------- @@ -66,16 +71,18 @@ public class XxlJobContext { private String handleMsg; - public XxlJobContext(long jobId, + public XxlJobContext(long jobId, String jobParam, - long jobLogTime, - String jobLogFileName, + long logId, + long logDateTime, + String logFileName, int shardIndex, int shardTotal) { this.jobId = jobId; this.jobParam = jobParam; - this.jobLogTime = jobLogTime; - this.jobLogFileName = jobLogFileName; + this.logId = logId; + this.logDateTime = logDateTime; + this.logFileName = logFileName; this.shardIndex = shardIndex; this.shardTotal = shardTotal; @@ -90,12 +97,16 @@ public class XxlJobContext { return jobParam; } - public String getJobLogFileName() { - return jobLogFileName; + public long getLogId() { + return logId; + } + + public long getLogDateTime() { + return logDateTime; } - public long getJobLogTime() { - return jobLogTime; + public String getLogFileName() { + return logFileName; } public int getShardIndex() { diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobHelper.java b/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobHelper.java index 838b0fd6..ae9e62b6 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobHelper.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobHelper.java @@ -18,7 +18,7 @@ import java.util.Date; */ public class XxlJobHelper { - // ---------------------- base info ---------------------- + // ---------------------- job info ---------------------- /** * current JobId @@ -48,20 +48,34 @@ public class XxlJobHelper { return xxlJobContext.getJobParam(); } - // ---------------------- for log ---------------------- + // ---------------------- log info ---------------------- /** * current job log time * * @return logDateTime */ - public static long getJobLogTime() { + public static long getLogId() { XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext(); if (xxlJobContext == null) { return -1; } - return xxlJobContext.getJobLogTime(); + return xxlJobContext.getLogId(); + } + + /** + * current job log time + * + * @return logDateTime + */ + public static long getLogDateTime() { + XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext(); + if (xxlJobContext == null) { + return -1; + } + + return xxlJobContext.getLogDateTime(); } /** @@ -69,16 +83,16 @@ public class XxlJobHelper { * * @return logFileName */ - public static String getJobLogFileName() { + public static String getLogFileName() { XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext(); if (xxlJobContext == null) { return null; } - return xxlJobContext.getJobLogFileName(); + return xxlJobContext.getLogFileName(); } - // ---------------------- for shard ---------------------- + // ---------------------- shard info ---------------------- /** * current ShardIndex @@ -171,7 +185,7 @@ public class XxlJobHelper { (appendLog != null ? appendLog : ""); // appendlog - String logFileName = xxlJobContext.getJobLogFileName(); + String logFileName = xxlJobContext.getLogFileName(); if (logFileName!=null && !logFileName.trim().isEmpty()) { XxlJobFileAppender.appendLog(logFileName, formatAppendLog); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java b/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java index 725dea94..54ea0fa3 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java @@ -69,7 +69,7 @@ public class ScriptJobHandler extends IJobHandler { } // log file - String logFileName = XxlJobContext.getXxlJobContext().getJobLogFileName(); + String logFileName = XxlJobContext.getXxlJobContext().getLogFileName(); // script params:0=param、1=分片序号、2=分片总数 String jobParam = XxlJobHelper.getJobParam(); diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java index 9000f40c..1082f01d 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java @@ -115,6 +115,7 @@ public class JobThread extends Thread{ XxlJobContext xxlJobContext = new XxlJobContext( triggerParam.getJobId(), triggerParam.getExecutorParams(), + triggerParam.getLogId(), triggerParam.getLogDateTime(), logFileName, triggerParam.getBroadcastIndex(), @@ -178,7 +179,7 @@ public class JobThread extends Thread{ } else { if (idleTimes > 30) { - if(triggerQueue.size() == 0) { // avoid concurrent trigger causes jobId-lost + if(triggerQueue.isEmpty()) { // avoid concurrent trigger causes jobId-lost XxlJobExecutor.removeJobThread(jobId, "excutor idle times over limit."); } } @@ -221,7 +222,7 @@ public class JobThread extends Thread{ } // callback trigger request in queue - while(triggerQueue !=null && triggerQueue.size()>0){ + while(triggerQueue !=null && !triggerQueue.isEmpty()){ TriggerRequest triggerParam = triggerQueue.poll(); if (triggerParam!=null) { // is killed diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java index 4252dbed..2417a36d 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java @@ -208,6 +208,7 @@ public class TriggerCallbackThread { -1, null, -1, + -1, logFileName, -1, -1));