Jactl brings virtual threads to Java 8 with a clever exception trick
Virtual Threads for a scripting language in Java 8 without Loom

Jactl, an embeddable scripting language for Java, implements continuations and virtual-thread-like behavior without Loom, targeting Java 8 and 11. By throwing lightweight exceptions that unwind the call stack, each Jactl frame saves its state into a chain of Continuation objects, which can be resumed later. This enables non-blocking execution in event-driven applications. The post details the mechanism, including async function tracking, resumption, checkpointing, and benchmarks showing minimal overhead.
The cost of throwing an exception is mostly in the generation of the stack trace that goes along with it. As long as you throw an exception that does not fill in the stack trace, it is actually very efficient.
- cchianel
I implemented continuations (required for Python generators) differently in my Python (AST) to Java (bytecode) translator. The switch dispatch to restore variables and jump to next location is the same, but instead of throwing an exception, I treated each function as its own class and stored the stack, variables, etc. on the class (relevant code: https://github.com/cdis-vm/cdis2java/blob/main/src/main/java...). When you "call" the generator, what you actually get is a new instance of that class, so multiple threads can call the function with different arguments.
Note: the code itself is far from production ready, do not use this!
- jaccomo
Author here: Jactl is a secure embeddable scripting language that compiles to bytecode and supports Java 8 and later versions. The article describes how Continuations were used to provide Virtual Thread-like behaviour for scripts.
Blocking operations suspend a script which is then resumed from where it left off once the operation completes.
- arvyy
As a related work regarding continuations, there was also a thesis by Andrea Bernardini (https://andrebask.github.io/thesis), with similar principal idea