Created
January 18, 2019 21:54
-
-
Save eleinadani/72847bbf90fb62c5d0af27f2a7406f53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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