From bae784aa246cbc234ade758cf82089b8ac1b3fb4 Mon Sep 17 00:00:00 2001 From: wxm <115806199+youfanx@users.noreply.github.com> Date: Tue, 24 Dec 2024 10:42:57 +0800 Subject: [PATCH] up --- .../src/main/java/org/rx/jdbc/SimpleORM.java | 2 + rxlib/src/main/java/org/rx/core/Tasks.java | 2 +- .../main/java/org/rx/spring/MxController.java | 22 ++++++---- .../main/java/org/rx/spring/SpringConfig.java | 41 +++++++++++++++++-- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/rxlib-x/src/main/java/org/rx/jdbc/SimpleORM.java b/rxlib-x/src/main/java/org/rx/jdbc/SimpleORM.java index 37e2588b..7bc3b92c 100644 --- a/rxlib-x/src/main/java/org/rx/jdbc/SimpleORM.java +++ b/rxlib-x/src/main/java/org/rx/jdbc/SimpleORM.java @@ -1,5 +1,6 @@ package org.rx.jdbc; +import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.rx.annotation.DbColumn; @@ -25,6 +26,7 @@ @RequiredArgsConstructor public class SimpleORM { + @Getter final JdbcExecutor executor; static final BiFunc, String> TO_UNDERSCORE_TABLE_MAPPING = t -> { diff --git a/rxlib/src/main/java/org/rx/core/Tasks.java b/rxlib/src/main/java/org/rx/core/Tasks.java index 643ad582..4e889311 100644 --- a/rxlib/src/main/java/org/rx/core/Tasks.java +++ b/rxlib/src/main/java/org/rx/core/Tasks.java @@ -75,7 +75,7 @@ public boolean isTerminated() { } @Override - public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { + public boolean awaitTermination(long timeout, TimeUnit unit) { return shutdown; } }; diff --git a/rxlib/src/main/java/org/rx/spring/MxController.java b/rxlib/src/main/java/org/rx/spring/MxController.java index ebf3add9..5026f088 100644 --- a/rxlib/src/main/java/org/rx/spring/MxController.java +++ b/rxlib/src/main/java/org/rx/spring/MxController.java @@ -48,15 +48,6 @@ public class MxController { @SneakyThrows @RequestMapping("health") public Object health(HttpServletRequest request) { - final String rt = "1"; - String multicast = request.getParameter("multicast"); - if (multicast != null) { - String group = request.getParameter("group"); - Integer mcId = Reflects.changeType(request.getParameter("mcId"), Integer.class); - NetEventWait.multicastLocal(Sockets.parseEndpoint(multicast), group, ifNull(mcId, 0)); - return rt; - } - final HttpHeaders headers = new HttpHeaders(); // headers.setContentType(MediaType.valueOf("text/plain;charset=UTF-8")); headers.setContentType(MediaType.TEXT_PLAIN); @@ -74,7 +65,18 @@ public Object health(HttpServletRequest request) { TraceHandler.INSTANCE.log("rx replay {}", buf); return new ResponseEntity<>(buf, headers, HttpStatus.OK); } + + final String rt = "1"; + ThreadPool.startTrace(null); try { + String multicast = request.getParameter("multicast"); + if (multicast != null) { + String group = request.getParameter("group"); + Integer mcId = Reflects.changeType(request.getParameter("mcId"), Integer.class); + NetEventWait.multicastLocal(Sockets.parseEndpoint(multicast), group, ifNull(mcId, 0)); + return rt; + } + switch (Integer.parseInt(x)) { case 1: Sys.diagnosticMx.setVMOption(request.getParameter("k"), request.getParameter("v")); @@ -137,6 +139,8 @@ public Object health(HttpServletRequest request) { return svrState(request); } catch (Throwable e) { return new ResponseEntity<>(String.format("%s\n%s", e, ExceptionUtils.getStackTrace(e)), headers, HttpStatus.OK); + } finally { + ThreadPool.endTrace(); } } diff --git a/rxlib/src/main/java/org/rx/spring/SpringConfig.java b/rxlib/src/main/java/org/rx/spring/SpringConfig.java index 70965fe3..f8d690ba 100644 --- a/rxlib/src/main/java/org/rx/spring/SpringConfig.java +++ b/rxlib/src/main/java/org/rx/spring/SpringConfig.java @@ -2,17 +2,23 @@ import org.rx.bean.Decimal; import org.rx.core.Reflects; +import org.rx.core.Tasks; import org.rx.net.AuthenticEndpoint; import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.Primary; import org.springframework.core.convert.converter.Converter; +import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.stereotype.Component; import javax.validation.Validation; import javax.validation.Validator; import java.io.File; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; @Configuration @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) @@ -29,10 +35,37 @@ public class SpringConfig // return (e, m, a) -> TraceHandler.INSTANCE.log(e); // } -// @Bean("defaultExecutorService") -// public ExecutorService executorService() { -// return Tasks.executor(); -// } + @Primary + @Bean + public AsyncTaskExecutor asyncTaskExecutorEx() { + return new AsyncTaskExecutor() { + @Override + public void execute(Runnable task, long startTimeout) { + Tasks.executor().execute(task); + } + + @Override + public Future submit(Runnable task) { + return Tasks.executor().submit(task); + } + + @Override + public Future submit(Callable task) { + return Tasks.executor().submit(task); + } + + @Override + public void execute(Runnable task) { + Tasks.executor().execute(task); + } + }; + } + + @Primary + @Bean + public ExecutorService executorServiceEx() { + return Tasks.executor(); + } @Bean public Validator validator() {