3 ms·
Node is taking the entirely opposite approach to Java and Go, so not sure why you're putting them in the same boat. Basically what Java is doing now, and what
by tsimionescu 3y ago
Node is taking the entirely opposite approach to Java and Go, so not sure why you're putting them in the same boat.
Basically what Java is doing now, and what Go did when it came out, is to turn the clock back on (explicit) async/await or promises/futures, and return to simpler threading+blocking IO APIs, while retaining the performance benefits of async code. This is achieved by integrating the blocking IO implementations with the thread scheduler, and by using user-space threads instead of expensive OS threads with their large stacks.
Of course, Java has other threading constructs than Go, but the core idea with Project Loom will be similar: you can just do something like
int[] xs = new int[N];
Thread ts = new Thread[N];
for (int i = 0; i < N; i++) {
ts[i] = new Thread(
()->{xs[i]=blockingRead();}
);
ts[i].start();
}
for (int i = 0; i < N; i++) {
ts[i].join();
}
Or something close to it, and you will get efficient threading even for large N.