From db4d8685f758032796b192d7cb6536744797f5f9 Mon Sep 17 00:00:00 2001 From: haozi Date: Thu, 15 Apr 2021 18:52:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E7=BA=BF=E7=A8=8B=E6=B1=A0?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E4=B8=8B=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../threadpool/ThreadPoolCommandItems.java | 40 ++++++++++++++++--- .../threadpool/ThreadPoolMonitorItems.java | 6 +-- .../jvm/threadpool/ThreadPoolProcessor.java | 1 + .../cmd/jvm/threadpool/ThreadPoolService.java | 2 +- .../proxy/controller/JvmController.java | 9 ++--- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolCommandItems.java b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolCommandItems.java index 0e145ee..5b03f1b 100644 --- a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolCommandItems.java +++ b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolCommandItems.java @@ -15,29 +15,35 @@ public enum ThreadPoolCommandItems { /** * 修改核心线程数 */ - CORE_POOL_SIZE("setCorePoolSize", (t, value) -> t.setCorePoolSize((Integer) value)), + CORE_POOL_SIZE("setCorePoolSize", (t, v) -> + t.setCorePoolSize(doubleToObject((Double) v, Integer.class)) + ), /** * 修改存活时间 */ - KEEP_ALIVE_TIME("setKeepAliveTime", (t, v) -> t.setKeepAliveTime((Long) v, TimeUnit.MILLISECONDS)), + KEEP_ALIVE_TIME("setKeepAliveTime", (t, v) -> + t.setKeepAliveTime(doubleToObject((Double) v, Long.class), TimeUnit.MILLISECONDS) + ), /** * 修改最大线程数 */ - MAXIMUM_POOL_SIZE("setMaximumPoolSize", (t, v) -> t.setMaximumPoolSize((Integer) v)), + MAXIMUM_POOL_SIZE("setMaximumPoolSize", (t, v) -> + t.setMaximumPoolSize(doubleToObject((Double) v, Integer.class)) + ), /** * 修改拒绝策略 */ REJECTED_EXECUTION_HANDLER("setRejectedExecutionHandler", (t, v) -> { for (RejectedExecutionHandler rejectedExecutionHandler : RejectedExecution.HANDLERS) { - if (rejectedExecutionHandler.getClass().getName().equals(v.toString())) { + if (rejectedExecutionHandler.getClass().getName().split("\\$")[1].equals(v.toString())) { t.setRejectedExecutionHandler(rejectedExecutionHandler); return; } } - new IllegalArgumentException("not found `RejectedExecutionHandler` for [" + v + "]"); + throw new IllegalArgumentException("not found `RejectedExecutionHandler` for [" + v + "]"); }), /** @@ -74,6 +80,30 @@ public enum ThreadPoolCommandItems { } } + /** + * dubbo转指定类型 + *

+ * gson数值默认转成double类型 + * + * @param n + * @param mClass + * @param + * @return + */ + private static T doubleToObject(Double n, Class mClass) { + if (n == null || mClass == null) { + return (T) n; + } + if (mClass == Integer.class) { + return (T) (Integer) n.intValue(); + } + + if (mClass == Long.class) { + return (T) (Long) n.longValue(); + } + throw new UnsupportedOperationException("can not to [" + mClass + "]"); + } + /** * 线程池拒绝策略 */ diff --git a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolMonitorItems.java b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolMonitorItems.java index 03f09b7..46b34c1 100644 --- a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolMonitorItems.java +++ b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolMonitorItems.java @@ -74,7 +74,7 @@ public enum ThreadPoolMonitorItems { * * @return */ - public static String key() { + public static String key(Object obj) { String name = Thread.currentThread().getName(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); StackTraceElement stackTraceElement = stackTrace[stackTrace.length - 1]; @@ -83,8 +83,8 @@ public enum ThreadPoolMonitorItems { .append(stackTraceElement.getClassName()) .append("[") .append(stackTraceElement.getMethodName()) - .append("]") - .append(stackTraceElement.hashCode()); + .append("]-") + .append(obj.hashCode()); return builder.toString(); } } diff --git a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolProcessor.java b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolProcessor.java index 20e6c53..b27f9d2 100644 --- a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolProcessor.java +++ b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolProcessor.java @@ -55,6 +55,7 @@ public class ThreadPoolProcessor implements Processor { ThreadPoolExecutor monitorThreadPool = service.getMonitor(threadPoolCommandBody.getKey()); if (monitorThreadPool == null) { log.warn("thread pool is null, key [{}]", key); + return; } log.debug("update [{}] thread pool, {}({})", key, methodName, arg); diff --git a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolService.java b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolService.java index c006cac..14a2c8a 100644 --- a/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolService.java +++ b/cubic-agent/src/main/java/com/cubic/agent/cmd/jvm/threadpool/ThreadPoolService.java @@ -83,7 +83,7 @@ public class ThreadPoolService implements CommonService, AgentChannelListener { * @param threadPoolExecutor */ public static void addMonitor(ThreadPoolExecutor threadPoolExecutor) { - threadPoolReferences.put(ThreadPoolMonitorItems.key(), new WeakReference<>(threadPoolExecutor)); + threadPoolReferences.put(ThreadPoolMonitorItems.key(threadPoolExecutor), new WeakReference<>(threadPoolExecutor)); } /** diff --git a/cubic-proxy/src/main/java/com/matrix/proxy/controller/JvmController.java b/cubic-proxy/src/main/java/com/matrix/proxy/controller/JvmController.java index dd4e0fe..0387954 100644 --- a/cubic-proxy/src/main/java/com/matrix/proxy/controller/JvmController.java +++ b/cubic-proxy/src/main/java/com/matrix/proxy/controller/JvmController.java @@ -1,14 +1,11 @@ package com.matrix.proxy.controller; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.cubic.proxy.common.constant.CommandCode; import com.matrix.proxy.service.JdkCommandService; import com.matrix.proxy.service.JvmDataService; import com.matrix.proxy.vo.ThreadPoolCommandVo; -import com.matrix.proxy.vo.ThreadPoolQueryVo; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -37,12 +34,12 @@ public class JvmController { * @return */ @RequestMapping("/threadPoolList") - public Map threadPoolPage(@RequestParam String instanceUid, @RequestParam String dayTime) { + public Map threadPoolPage(@RequestParam(required = false) String instanceUid, @RequestParam String dayTime) { - if(StringUtils.isEmpty(instanceUid)){ + if (StringUtils.isEmpty(instanceUid)) { return new HashMap<>(); } - return jvmDataService.threadPoolDataPage(instanceUid,dayTime); + return jvmDataService.threadPoolDataPage(instanceUid, dayTime); } -- Gitee