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() { + } + +}