Skip to content

Instantly share code, notes, and snippets.

@eleinadani
Created January 18, 2019 21:54
Show Gist options
  • Save eleinadani/72847bbf90fb62c5d0af27f2a7406f53 to your computer and use it in GitHub Desktop.
Save eleinadani/72847bbf90fb62c5d0af27f2a7406f53 to your computer and use it in GitHub Desktop.
const Thread = Java.type('java.lang.Thread')
// `function run()` is converted to a Java Runnable instance by GraalVM
const t = new Thread(function run() {
// this will never be executed, as an exception will be thrown
console.log('hello from another thread!')
});
// creating a thread does not imply concurrent access to a shared JS object.
// starting the thread, however, will result in a concurrent access to the
// shared Runnable object (that is, the JavaScript 'run' function above).
t.start();
// An IllegalStateException will be thrown as soon as the new thread starts.
t.join();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment