[英]Concept of JVM thread and relation to OS thread
这是我对 CPU 和线程的基本理解(天真!)。 处理器每个内核可以运行一个线程。
我的笔记本电脑上的系统信息如下所示
处理器 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz, 2112 Mhz, 4 Core(s), 8 Logical Processor(s) **可以并行运行 8 个线程 **
为了验证我的理解,我创建了一个 Spring Boot(嵌入式 tomcat)来处理每个请求
@GetMapping("/ping")
public String ping(@RequestParam String id) throws InterruptedException {
System.out.println(MessageFormat.format("The request id is {0}", id));
int i = Integer.parseInt(id);
long now = System.currentTimeMillis();
long period = 5000L;
long later = System.currentTimeMillis();
if (i % 2 == 1) {
while (later - now <= period) {
later = System.currentTimeMillis();
}
}
return PING_SUCCESSFUL;
}
我还将 tomcat 上的最大线程数设置为以下
server.tomcat.max-threads=200
我现在使用 Apache JMeter 在 1 秒内触发 200 个请求
我的期望是我的系统只能运行 8 个线程,因此请求的总运行时间应该至少为(200 / 8)*5 = 125 秒
然而,即使是 125 秒也是不现实的,因为我的系统上还有其他应用程序在运行,比如浏览器、JMeter、IntelliJ,它们应该自己考虑一些线程。
我观察到一个对比行为 - 观察到的总运行时间为5 秒。 系统怎么可能运行超过限制的线程数? (我发现对线程以及底层处理器似乎如何并行化线程有一些理解错误)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.