1 Star 0 Fork 3

睿凡/sharecode

forked from dwing/sharecode 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Loom2.java 1002 Bytes
一键复制 编辑 原始数据 按行查看 历史
dwing 提交于 2024-07-12 17:41 +08:00 . java: move Unsafe calls to UnsafeUtil; fix warnings
import java.util.concurrent.Executor;
import jdk.internal.vm.Continuation;
import jdk.internal.vm.ContinuationScope;
import util.UnsafeUtil;
// java --add-opens java.base/jdk.internal.vm=ALL-UNNAMED Loom2
public class Loom2 {
public static void main(String[] args) throws Exception {
var tb = Thread.ofVirtual();
UnsafeUtil.getField(tb.getClass(), "scheduler").set(tb, (Executor)Runnable::run);
var cs = new ContinuationScope("VirtualThreads");
var c = new Continuation(cs, () -> {
System.out.println("in Continuation: begin " + Thread.currentThread());
Continuation.yield(cs);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("in Continuation: end " + Thread.currentThread());
});
System.out.println("main: begin " + Thread.currentThread());
c.run();
System.out.println("main: continue " + Thread.currentThread());
c.run();
System.out.println("main: end " + Thread.currentThread());
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/lcpsky/sharecode.git
git@gitee.com:lcpsky/sharecode.git
lcpsky
sharecode
sharecode
main

搜索帮助