Questions tagged [virtual-threads]
10 questions
7
votes
2 answers
Is it possible to create a ThreadLocal for the carrier thread of a Java virtual thread?
JEP-425: Virtual Threads states that a new virtual thread "should be created for every application task" and makes twice a reference to the possibility of having "millions" of virtual threads running in the JVM.
The same JEP implies that each…

Martin Andersson
- 18,072
- 9
- 87
- 115
4
votes
1 answer
Why does JMC (JDK Mission Control) not show any virtual thread events?
I have a small SpringBoot app with 1 RestController with following method:
@GetMapping("/current-thread")
String currentThread() throws InterruptedException {
var msg = new Msg();
Thread.startVirtualThread(() -> {
…

Java User
- 43
- 4
4
votes
2 answers
Thread.currentThread().getName() returns empty string "" for Virtual Threads created via Executors.newVirtualThreadPerTaskExecutor()
I am working with Java 19. I have tried to use newly introduced virtual threads as follows:
public static void main(String[] args) {
System.out.println("Started with virutal threads");
try (ExecutorService virtualService =…

fascynacja
- 1,625
- 4
- 17
- 35
1
vote
0 answers
How does a virtual thread know that its blocking operation has done?
As I understand, a virtual thread is actually a "task", not a thread. A virtual thread is executed by carrier threads inside a ForkJoinPool. When a virtual thread encounters blocking I/O and goes into a waiting state, it stops its work and saves…

ParkCheolu
- 1,175
- 2
- 14
- 30
1
vote
2 answers
How to detect virtual threads on java 19
Lets say I want to ship a program that runs on java 17 as that is what is available widely, but use reflection to detect if im running on a vm with the ability to produce a thread factory via Thread.ofVirtual().name("abc").factory(). Java prohibits…

Dave Ankin
- 1,060
- 2
- 9
- 20
1
vote
0 answers
Why does joining a no-op virtual thread in a static initialiser block indefinitely?
Note: I'm well aware that creating threads in static initialisers is discouraged. Yet, exploring edge cases can provide interesting insight and uncover undesired behaviour or bugs. Hence this question.
Experimenting with virtual threads in Java 20,…

michid
- 10,536
- 3
- 32
- 59
0
votes
0 answers
How to inspect Virtual Threads on a running JVM?
I have been using Project Loom to revive a game server - it's very old code that was written back when green threads were a thing, so writing a server on one-thread-per-connection model was not unreasonable - and it works quite well, in particular…

chesterbr
- 2,940
- 3
- 29
- 26
0
votes
0 answers
Kotlin/Java parallel stream on virtual threads
I have project in kotlin with Java 19 (with experimental features on). I have code:
private val virtualExecutor = Executors.newVirtualThreadPerTaskExecutor()
private fun countTenantsConsumption(
paged: Page,
command:…

lukisp
- 1,031
- 3
- 14
- 27
0
votes
0 answers
Virtual thread performance in IntSteram vs regular for loop
I'm trying to create 100k virtual threads with simple print statements. When I use the below code, the estimated execution time is 2 milliseconds:
List < Thread > threads = IntStream.of(0, 100000)
.mapToObj(it -> Thread.ofVirtual().unstarted(() ->…

Rahul Raj
- 3,197
- 5
- 35
- 55
0
votes
0 answers
Epoll mechanism when using virtual threads
I am implementing a tcp server based on epoll and JAVA virtual threads, I created a platform thread for infinitely epoll_wait() for incoming messages or connections, and for each connection established, a virtual thread with a BlockingQueue is…

benrush
- 43
- 4