-
-
Save DasBrain/2aebc453894db682d92fe78ae0cf56e2 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
package pw.dasbrain.test.loom; | |
import java.util.concurrent.ForkJoinPool; | |
public class CancelVT { | |
public static void main(String[] args) { | |
Runnable r = () -> { | |
try { | |
System.out.println("Running"); | |
Thread.sleep(500); | |
} catch (InterruptedException e) { | |
System.out.println("Interrupted"); | |
} finally { | |
System.out.println("Finally"); | |
} | |
}; | |
try (var pool = new ForkJoinPool()) { | |
Thread.builder().virtual(pool).task(r).start(); | |
// Assume more virtual threads are started in that pool, one completes after 250ms. | |
Thread.sleep(250); | |
System.out.println("shutdown pool"); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("done"); | |
} | |
} |
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
Running | |
shutdown pool | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment