java Vertx 事件循环共享同一个线程吗?还是一对一?
Do java Vertx event-loops share the same thread? Or is it one to one?
这是关于 java Vertx 事件循环的。一个线程是否附加到一个事件循环?还是单个线程可以 运行 多个事件循环?
通常情况下,事件循环本身就是一个单独的线程(不应该被阻塞)。但是可以有多个事件循环。
Instead of a single event loop, each Vertx instance maintains several event loops. By default, we choose the number based on the number of available cores on the machine, but this can be overridden.
A Vert.x instance maintains N event loop threads (where N by default is core*2) by default.
Tcheutchoua Steve 的回答是正确的。
For event loop tasks, size of the thread pool is two times the CPU count by default
您可以使用该示例自己查看:
class MyVerticle extends AbstractVerticle {
private final Map<String, AtomicInteger> threadCounts;
MyVerticle(Map<String, AtomicInteger> threadCounts) {
this.threadCounts = threadCounts;
}
@Override
public void start() {
threadCounts.computeIfAbsent(Thread.currentThread().getName(),
t -> new AtomicInteger(0)).incrementAndGet();
}
}
如果您想更多地了解Vert.x事件循环,您可以阅读我关于该主题的文章:
https://alexey-soshin.medium.com/understanding-vert-x-event-loop-46373115fb3e
这是关于 java Vertx 事件循环的。一个线程是否附加到一个事件循环?还是单个线程可以 运行 多个事件循环?
通常情况下,事件循环本身就是一个单独的线程(不应该被阻塞)。但是可以有多个事件循环。
Instead of a single event loop, each Vertx instance maintains several event loops. By default, we choose the number based on the number of available cores on the machine, but this can be overridden.
A Vert.x instance maintains N event loop threads (where N by default is core*2) by default.
Tcheutchoua Steve 的回答是正确的。
For event loop tasks, size of the thread pool is two times the CPU count by default
您可以使用该示例自己查看:
class MyVerticle extends AbstractVerticle {
private final Map<String, AtomicInteger> threadCounts;
MyVerticle(Map<String, AtomicInteger> threadCounts) {
this.threadCounts = threadCounts;
}
@Override
public void start() {
threadCounts.computeIfAbsent(Thread.currentThread().getName(),
t -> new AtomicInteger(0)).incrementAndGet();
}
}
如果您想更多地了解Vert.x事件循环,您可以阅读我关于该主题的文章:
https://alexey-soshin.medium.com/understanding-vert-x-event-loop-46373115fb3e