From 6429a02e97256291d6ba071bc14de53b730949ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E8=9C=97=E7=89=9B?=
<1003271829@qq.com>
Date: Sat, 9 Dec 2023 10:44:11 +0800
Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=B8=8D=E5=A4=84=E7=90=86?=
=?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=9A=84=E6=97=B6=E5=80=99=20=E4=B9=9F?=
=?UTF-8?q?=E5=8D=A0=E7=94=A8=E5=A4=A7=E9=87=8F=E7=9A=84=E5=86=85=E5=AD=98?=
=?UTF-8?q?=20=E8=AF=A5=E5=A6=82=E4=BD=95=E6=8E=92=E6=9F=A5=E5=B9=B6?=
=?UTF-8?q?=E8=A7=A3=E5=86=B3=EF=BC=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../jvm-optimize/pom.xml | 95 +++++++++++++++++++
.../jvmoptimize/JvmOptimizeApplication.java | 13 +++
.../woniu/jvmoptimize/config/LoginConfig.java | 17 ++++
.../jvmoptimize/config/UserInterceptor.java | 32 +++++++
.../controller/DemoMemoryController.java | 26 +++++
.../woniu/jvmoptimize/entity/UserData.java | 5 +
.../src/main/resources/application.yml | 18 ++++
.../JvmOptimizeApplicationTests.java | 13 +++
8 files changed, 219 insertions(+)
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/pom.xml
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/JvmOptimizeApplication.java
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/LoginConfig.java
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/UserInterceptor.java
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/controller/DemoMemoryController.java
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/entity/UserData.java
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/resources/application.yml
create mode 100644 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/test/java/com/woniu/jvmoptimize/JvmOptimizeApplicationTests.java
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/pom.xml b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/pom.xml
new file mode 100644
index 0000000..4411b8a
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/pom.xml
@@ -0,0 +1,95 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.7.12
+
+
+ com.itheima
+ jvm-optimize
+ 0.0.1-SNAPSHOT
+ jvm-optimize
+ jvm-optimize
+
+ 8
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.apache.commons
+ commons-lang3
+ 3.12.0
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+
+ org.openjdk.jol
+ jol-core
+ 0.9
+
+
+
+ org.springframework.data
+ spring-data-commons
+
+
+
+ cn.hutool
+ hutool-all
+ 5.8.16
+
+
+
+ com.github.ben-manes.caffeine
+ caffeine
+ 2.9.3
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
+
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/JvmOptimizeApplication.java b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/JvmOptimizeApplication.java
new file mode 100644
index 0000000..9c3a6fd
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/JvmOptimizeApplication.java
@@ -0,0 +1,13 @@
+package com.woniu.jvmoptimize;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class JvmOptimizeApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(JvmOptimizeApplication.class, args);
+ }
+
+}
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/LoginConfig.java b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/LoginConfig.java
new file mode 100644
index 0000000..faba1ee
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/LoginConfig.java
@@ -0,0 +1,17 @@
+package com.woniu.jvmoptimize.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class LoginConfig implements WebMvcConfigurer {
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ //注册拦截器
+ registry.addInterceptor(new UserInterceptor())
+ .addPathPatterns("/dealMemory/**");
+
+ }
+}
\ No newline at end of file
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/UserInterceptor.java b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/UserInterceptor.java
new file mode 100644
index 0000000..eaafad9
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/config/UserInterceptor.java
@@ -0,0 +1,32 @@
+package com.woniu.jvmoptimize.config;
+
+import com.woniu.jvmoptimize.entity.UserData;
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * 拦截器的实现,模拟放入数据到threadlocal中
+ */
+public class UserInterceptor implements HandlerInterceptor {
+
+ public static ThreadLocal userData = new ThreadLocal<>();
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ userData.set(new UserData());
+ return true;
+ }
+
+ @Override
+ public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
+// userData.remove();
+ }
+
+ @Override
+ public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+ userData.remove();
+ }
+}
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/controller/DemoMemoryController.java b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/controller/DemoMemoryController.java
new file mode 100644
index 0000000..01836d5
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/controller/DemoMemoryController.java
@@ -0,0 +1,26 @@
+package com.woniu.jvmoptimize.controller;
+
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * -Xmx1g -Xms1g
+ * 系统不处理业务的时候 也占用大量的内存 该如何排查并解决?
+ */
+@RestController
+@RequestMapping("/dealMemory")
+public class DemoMemoryController {
+
+ @GetMapping
+ public ResponseEntity test() {
+ error();
+ return ResponseEntity.ok().build();
+ }
+
+ private void error() {
+ throw new RuntimeException("出错了");
+ }
+
+}
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/entity/UserData.java b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/entity/UserData.java
new file mode 100644
index 0000000..fe31e3f
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/java/com/woniu/jvmoptimize/entity/UserData.java
@@ -0,0 +1,5 @@
+package com.woniu.jvmoptimize.entity;
+
+public class UserData {
+ byte[] data = new byte[1024 * 1024 * 10]; //模拟保存10m的用户数据
+}
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/resources/application.yml b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/resources/application.yml
new file mode 100644
index 0000000..39a79cc
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/main/resources/application.yml
@@ -0,0 +1,18 @@
+
+#设置应用名
+spring:
+ application:
+ name: jvm-service
+
+
+
+
+server:
+ port: 8881
+ tomcat:
+ threads:
+ min-spare: 100
+ max: 500
+
+
+
diff --git a/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/test/java/com/woniu/jvmoptimize/JvmOptimizeApplicationTests.java b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/test/java/com/woniu/jvmoptimize/JvmOptimizeApplicationTests.java
new file mode 100644
index 0000000..2250a82
--- /dev/null
+++ b/系统不处理业务的时候 也占用大量的内存 该如何排查并解决?/jvm-optimize/src/test/java/com/woniu/jvmoptimize/JvmOptimizeApplicationTests.java
@@ -0,0 +1,13 @@
+package com.woniu.jvmoptimize;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class JvmOptimizeApplicationTests {
+
+ @Test
+ void contextLoads() {
+ }
+
+}