说明
一般我们发现内存持续增长,但是并没有得到释放,我们就需要排查是否内存泄露
代码模拟
通过ThreadLocal模拟内存泄露
为什么ThreadLocal会内存泄露?参考:《ThreadLocal》
@RequestMapping("/testController") @Controller public class TestController { @RequestMapping(value = "/test3") @ResponseBody public String test3() { ThreadLocal localVariable = new ThreadLocal(); localVariable.set(new Byte[4096 * 1024]);// 为线程添加变量 return "success"; } }
AB压测模拟
ab使用例子:《压测工具-ab》
ab -c 500 -n 1000 localhost:8999/testController/test3