5回复
3年前
Xss/ThreadStackSize配置真正含义是什么?
如下代码:
private static final ThreadPoolExecutor EXECUTOR = (ThreadPoolExecutor) Executors.newCachedThreadPool();
public static void main(String[] args) {
for (; ; ) {
EXECUTOR.execute(() -> {
try {
TimeUnit.MILLISECONDS.sleep(200L);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
}
启动参数-Xss1m,当开启到线程数有20K+时,整个进程使用的内存也只有500M+,按照线程栈1m*20K+≈2G才对,这还不算堆内存。为什么只占用了500M呢?有劳大佬解惑!
3634 阅读