Context objects, or multiple Worker threads.
Contexts can be created, but they should be used by one thread at a time.
Context cannot be accessed by two or more threads, concurrently, but it is possible to access the same
Context from multiple threads using proper syncronization, to ensure that concurrent access never happens.
Contextobjects can be executed in multiple threads.
Contextcan be accessed from multiple threads when proper synchronization is used.
Multithreading with Node.js
On the contrary, a Java object created with GraalVM Java interoperability (e.g., using
Java.type()) can be shared between Node.js Workers.
This allows multi-threaded Node.js applications to share Java objects.
The GraalVM Node.js unit tests contain several examples of multi-threaded Node.js applications. The most notable examples show how:
- Node.js worker threads can execute Java code.
- Java objects can be shared between Node.js worker threads.
Promiseobjects can be used to
awaiton messages from workers, using Java objects to bind promises to worker messages.