底层优化

v1.7
xueli.xue 8 years ago
parent 4760187247
commit 7b3d53fa1c

@ -857,6 +857,6 @@ XXL-JOB托管在Github上如有问题可在 [ISSUES](https://github.com/xuxue
更多接入公司欢迎在github [登记](https://github.com/xuxueli/xxl-job/issues/1 ) 更多接入公司欢迎在github [登记](https://github.com/xuxueli/xxl-job/issues/1 )
--- ---
#### 支持的话可以扫一扫,支持 [XXL系列](https://github.com/xuxueli) 的建设 #### 支持的话可以扫一扫,支持 [XXL系列](https://github.com/xuxueli) 的建设
![输入图片说明](http://images2015.cnblogs.com/blog/554415/201605/554415-20160513183306234-1939652116.png "在这里输入图片标题") ![输入图片说明](http://images2015.cnblogs.com/blog/554415/201605/554415-20160513183306234-1939652116.png "在这里输入图片标题")

@ -20,7 +20,7 @@ package com.xxl.job.admin.core.jobbean;
//import com.xxl.job.client.util.JacksonUtil; //import com.xxl.job.client.util.JacksonUtil;
//import com.xxl.job.core.model.XxlJobInfo; //import com.xxl.job.core.model.XxlJobInfo;
//import com.xxl.job.core.model.XxlJobLog; //import com.xxl.job.core.model.XxlJobLog;
//import com.xxl.job.core.thread.JobMonitorHelper; //import com.xxl.job.core.thread.JobFailMonitorHelper;
//import com.xxl.job.core.util.DynamicSchedulerUtil; //import com.xxl.job.core.util.DynamicSchedulerUtil;
// //
///** ///**
@ -84,7 +84,7 @@ package com.xxl.job.admin.core.jobbean;
// // update trigger info // // update trigger info
// DynamicSchedulerUtil.xxlJobLogDao.updateTriggerInfo(jobLog); // DynamicSchedulerUtil.xxlJobLogDao.updateTriggerInfo(jobLog);
// DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(jobLog); // DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(jobLog);
// JobMonitorHelper.monitor(jobLog.getId()); // JobFailMonitorHelper.monitor(jobLog.getId());
// logger.info(">>>>>>>>>>> xxl-job trigger end, jobLog.id:{}, jobLog:{}", jobLog.getId(), jobLog); // logger.info(">>>>>>>>>>> xxl-job trigger end, jobLog.id:{}, jobLog:{}", jobLog.getId(), jobLog);
// //
// } // }

@ -6,7 +6,7 @@ import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog; import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum; import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
import com.xxl.job.admin.core.thread.JobMonitorHelper; import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper; import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
import com.xxl.job.core.biz.ExecutorBiz; import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
@ -87,7 +87,7 @@ public class RemoteHttpJobBean extends QuartzJobBean {
XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog); XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);
// monitor triger // monitor triger
JobMonitorHelper.monitor(jobLog.getId()); JobFailMonitorHelper.monitor(jobLog.getId());
logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId()); logger.debug(">>>>>>>>>>> xxl-job trigger end, jobId:{}", jobLog.getId());
} }

@ -2,7 +2,7 @@ package com.xxl.job.admin.core.schedule;
import com.xxl.job.admin.core.jobbean.RemoteHttpJobBean; import com.xxl.job.admin.core.jobbean.RemoteHttpJobBean;
import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.thread.JobMonitorHelper; import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper; import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
import com.xxl.job.admin.dao.IXxlJobGroupDao; import com.xxl.job.admin.dao.IXxlJobGroupDao;
import com.xxl.job.admin.dao.IXxlJobInfoDao; import com.xxl.job.admin.dao.IXxlJobInfoDao;
@ -43,7 +43,7 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
JobRegistryMonitorHelper.getInstance().start(); JobRegistryMonitorHelper.getInstance().start();
// admin monitor run // admin monitor run
JobMonitorHelper.getInstance().start(); JobFailMonitorHelper.getInstance().start();
} }
// destroy // destroy
@ -52,7 +52,7 @@ public final class XxlJobDynamicScheduler implements ApplicationContextAware, In
JobRegistryMonitorHelper.getInstance().toStop(); JobRegistryMonitorHelper.getInstance().toStop();
// admin monitor stop // admin monitor stop
JobMonitorHelper.getInstance().toStop(); JobFailMonitorHelper.getInstance().toStop();
serverFactory.destroy(); serverFactory.destroy();
} }

@ -19,11 +19,11 @@ import java.util.concurrent.*;
* job monitor instance * job monitor instance
* @author xuxueli 2015-9-1 18:05:56 * @author xuxueli 2015-9-1 18:05:56
*/ */
public class JobMonitorHelper { public class JobFailMonitorHelper {
private static Logger logger = LoggerFactory.getLogger(JobMonitorHelper.class); private static Logger logger = LoggerFactory.getLogger(JobFailMonitorHelper.class);
private static JobMonitorHelper instance = new JobMonitorHelper(); private static JobFailMonitorHelper instance = new JobFailMonitorHelper();
public static JobMonitorHelper getInstance(){ public static JobFailMonitorHelper getInstance(){
return instance; return instance;
} }
@ -39,7 +39,7 @@ public class JobMonitorHelper {
while (!toStop) { while (!toStop) {
try { try {
logger.debug(">>>>>>>>>>> job monitor beat ... "); logger.debug(">>>>>>>>>>> job monitor beat ... ");
Integer jobLogId = JobMonitorHelper.instance.queue.take(); Integer jobLogId = JobFailMonitorHelper.instance.queue.take();
if (jobLogId != null && jobLogId > 0) { if (jobLogId != null && jobLogId > 0) {
logger.debug(">>>>>>>>>>> job monitor heat success, JobLogId:{}", jobLogId); logger.debug(">>>>>>>>>>> job monitor heat success, JobLogId:{}", jobLogId);
XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(jobLogId); XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(jobLogId);
@ -51,7 +51,7 @@ public class JobMonitorHelper {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
JobMonitorHelper.monitor(jobLogId); JobFailMonitorHelper.monitor(jobLogId);
} }
if (ReturnT.SUCCESS_CODE==log.getTriggerCode() && ReturnT.SUCCESS_CODE==log.getHandleCode()) { if (ReturnT.SUCCESS_CODE==log.getTriggerCode() && ReturnT.SUCCESS_CODE==log.getHandleCode()) {
// pass // pass

@ -1,16 +0,0 @@
//package com.xxl.job.core.glue.loader;
//
///**
// * code source loader
// * @author xuxueli 2016-1-2 20:01:39
// */
//public interface GlueLoader {
//
// /**
// * load code source by name, ensure every load is the latest.
// * @param jobId
// * @return code source
// */
// public String load(int jobId);
//
//}

@ -1,30 +0,0 @@
//package com.xxl.job.core.glue.loader.impl;
//
//import com.xxl.job.core.glue.loader.GlueLoader;
//import com.xxl.job.core.util.DBUtil;
//
//import javax.sql.DataSource;
//import java.util.List;
//import java.util.Map;
//
///**
// * Created by xuxueli on 16/9/30.
// */
//public class DbGlueLoader implements GlueLoader {
//
// private DataSource dataSource;
// public void setDataSource(DataSource dataSource) {
// this.dataSource = dataSource;
// }
//
// @Override
// public String load(int jobId) {
// String sql = "SELECT glue_source FROM XXL_JOB_QRTZ_TRIGGER_INFO WHERE id = ?";
// List<Map<String, Object>> result = DBUtil.query(dataSource, sql, new Object[]{jobId});
// if (result!=null && result.size()==1 && result.get(0)!=null && result.get(0).get("glue_source")!=null ) {
// return (String) result.get(0).get("glue_source");
// }
// return null;
// }
//
//}

@ -20,6 +20,12 @@ public class XxlJobLogger {
*/ */
public static void log(String appendLog) { public static void log(String appendLog) {
// logFileName
String logFileName = XxlJobFileAppender.contextHolder.get();
if (logFileName==null || logFileName.trim().length()==0) {
return;
}
// "yyyy-MM-dd HH:mm:ss [ClassName]-[MethodName]-[LineNumber]-[ThreadName] log"; // "yyyy-MM-dd HH:mm:ss [ClassName]-[MethodName]-[LineNumber]-[ThreadName] log";
StackTraceElement[] stackTraceElements = new Throwable().getStackTrace(); StackTraceElement[] stackTraceElements = new Throwable().getStackTrace();
StackTraceElement callInfo = stackTraceElements[1]; StackTraceElement callInfo = stackTraceElements[1];
@ -34,7 +40,6 @@ public class XxlJobLogger {
String formatAppendLog = stringBuffer.toString(); String formatAppendLog = stringBuffer.toString();
// appendlog // appendlog
String logFileName = XxlJobFileAppender.contextHolder.get();
XxlJobFileAppender.appendLog(logFileName, formatAppendLog); XxlJobFileAppender.appendLog(logFileName, formatAppendLog);
logger.warn("[{}]: {}", logFileName, formatAppendLog); logger.warn("[{}]: {}", logFileName, formatAppendLog);

@ -106,27 +106,29 @@ public class JobThread extends Thread{
String logFileName = XxlJobFileAppender.makeLogFileName(new Date(triggerParam.getLogDateTim()), triggerParam.getLogId()); String logFileName = XxlJobFileAppender.makeLogFileName(new Date(triggerParam.getLogDateTim()), triggerParam.getLogId());
XxlJobFileAppender.contextHolder.set(logFileName); XxlJobFileAppender.contextHolder.set(logFileName);
XxlJobLogger.log("----------- xxl-job job execute start -----------"); XxlJobLogger.log("<br>----------- xxl-job job execute start -----------<br>----------- Params:" + handlerParams);
executeResult = handler.execute(handlerParams); executeResult = handler.execute(handlerParams);
if (executeResult == null) { if (executeResult == null) {
executeResult = ReturnT.FAIL; executeResult = ReturnT.FAIL;
} }
XxlJobLogger.log("<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:" + executeResult);
} catch (Exception e) { } catch (Exception e) {
if (toStop) { if (toStop) {
XxlJobLogger.log("<br>----------- xxl-job toStop, stopReason:" + stopReason); XxlJobLogger.log("<br>----------- JobThread toStop, stopReason:" + stopReason);
} }
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter)); e.printStackTrace(new PrintWriter(stringWriter));
String errorMsg = stringWriter.toString(); String errorMsg = stringWriter.toString();
XxlJobLogger.log("JobThread Exception:" + errorMsg); executeResult = new ReturnT<String>(ReturnT.FAIL_CODE, errorMsg);
executeResult = new ReturnT<String>(ReturnT.FAIL_CODE, stringWriter.toString()); XxlJobLogger.log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------");
} }
XxlJobLogger.log("----------- xxl-job job execute end ----------- <br> " +
"Look : ExecutorParams:"+ handlerParams +", Code:"+ executeResult.getCode() +", Msg:" + executeResult.getMsg());
// callback handler info // callback handler info
if (!toStop) { if (!toStop) {

Loading…
Cancel
Save