Skip to content

Commit 6a205be

Browse files
committed
添加 虚拟线程工具示例
1 parent 828bf1a commit 6a205be

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/test/java/demo/VirtualCom.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package demo;
2+
3+
import org.noear.solon.annotation.Managed;
4+
import org.noear.solon.core.bean.LifecycleBean;
5+
import org.noear.solon.core.util.ThreadsUtil;
6+
7+
/**
8+
*
9+
* @author noear 2026/1/5 created
10+
*
11+
*/
12+
@Managed
13+
public class VirtualCom implements LifecycleBean {
14+
@Override
15+
public void start() throws Throwable {
16+
try {
17+
ThreadsUtil.newVirtualThreadPerTaskExecutor().submit(() -> {
18+
System.out.println("a: " + Thread.currentThread().getName());
19+
});
20+
21+
ThreadsUtil.newVirtualThreadPerTaskExecutor("test-v1-").submit(() -> {
22+
System.out.println("b: " + Thread.currentThread().getName());
23+
});
24+
25+
26+
ThreadsUtil.newVirtualThreadFactory().newThread(() -> {
27+
System.out.println("c: " + Thread.currentThread().getName());
28+
}).start();
29+
30+
ThreadsUtil.newVirtualThreadFactory("test-v2-").newThread(() -> {
31+
System.out.println("d: " + Thread.currentThread().getName());
32+
}).start();
33+
} catch (Throwable e) {
34+
e.printStackTrace();
35+
}
36+
37+
Thread.sleep(1000);
38+
}
39+
}

0 commit comments

Comments
 (0)