Java NIO non-blocking mode vs node.js asynchronous operation Java NIO non-blocking mode vs node.js asynchronous operation multithreading multithreading

Java NIO non-blocking mode vs node.js asynchronous operation


Asynchrony in general, and NIO in particular, are not necessarily backed by single thread, they can be supported by multiple threads to increase performance. However, multithreading requires additional synchronization (not complex, but accurate). Since javascript lacks synchronization utilities, Node.js has to use single thread. Java asynchronous frameworks can use multiple threads.

Apendix

Why is Node.js single-threaded by design? From Understanding Node.js:

"So I don't have to worry about code accessing the same datastructures at the same time?"

You got it! That's the entire beauty of JavaScriptssingle-threaded/event loop design!

So the most likely cause of single-threaded design is to please javascript programmers, which, en masse, are not familiar with synchronization concepts.


No. Non-blocking means that the operations don't block, and they tell you what they did. Asynchronous means they the operations continue in parallel and call you back when they finish. They are completely different programming paradigms.