提交 5c2bcb9f 编写于 作者: X xueli.xue

任务回调队列 + 任务执行队列,poll改为take;修复一处可能导致cpu占满的问题

上级 2477a85d
......@@ -192,7 +192,7 @@ public class HandlerRepository {
public void run() {
while(true){
try {
HashMap<String, String> item = callBackQueue.poll();
HashMap<String, String> item = callBackQueue.take();
if (item != null) {
RemoteCallBack callback = null;
try {
......@@ -201,7 +201,7 @@ public class HandlerRepository {
logger.info("HandlerThread Exception:", e);
}
logger.info(">>>>>>>>>>> xxl-job callback , params:{}, result:{}", new Object[]{item, callback});
}
}
} catch (Exception e) {
e.printStackTrace();
}
......
package com.xxl.job.core.handler;
import com.xxl.job.core.handler.HandlerRepository.HandlerParamEnum;
import com.xxl.job.core.handler.IJobHandler.JobHandleStatus;
import com.xxl.job.core.log.XxlJobFileAppender;
import com.xxl.job.core.util.HttpUtil;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.xxl.job.core.handler.HandlerRepository.HandlerParamEnum;
import com.xxl.job.core.handler.IJobHandler.JobHandleStatus;
import com.xxl.job.core.log.XxlJobFileAppender;
import com.xxl.job.core.util.HttpUtil;
/**
* handler thread
......@@ -57,7 +55,7 @@ public class HandlerThread extends Thread{
public void run() {
while(!toStop){
try {
Map<String, String> handlerData = handlerDataQueue.poll();
Map<String, String> handlerData = handlerDataQueue.take();
if (handlerData!=null) {
i= 0;
String log_address = handlerData.get(HandlerParamEnum.LOG_ADDRESS.name());
......@@ -103,17 +101,6 @@ public class HandlerThread extends Thread{
params.put("msg", "人工手动终止[业务运行中,被强制终止]");
HandlerRepository.pushCallBack(HttpUtil.addressToUrl(log_address), params);
}
} else {
i++;
logIdSet.clear();
try {
TimeUnit.MILLISECONDS.sleep(i * 100);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (i>5) {
i= 0;
}
}
} catch (Exception e) {
logger.info("HandlerThread Exception:", e);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册