Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
36 views

Is it possible to use virtual threads from Kotlin in an Android project as of current date?

I'm reading a book about Kotlin coroutines which explains the possibility to create a custom dispatcher which schedules virtual threads and also provides code to test the performance. Is it possible ...
Rosen Dimov's user avatar
  • 1,145
1 vote
2 answers
171 views

Is it a good idea to use CompletableFuture in combination with StructuredTaskScope?

I already have an implementation using CompletableFuture with Executors.newVirtualThreadPerTaskExecutor as executorService. For example, I have a code block, CompletableFuture<MyClass> ...
Arafat's user avatar
  • 33
2 votes
1 answer
184 views

TraceId propagation to virtual thread

My application to handle upstream request calls 2 downstream systems (by REST). As calls are parallelizable, I would like to use virtual threads, by StructuredTaskScope.fork() or Executors....
michaldo's user avatar
  • 4,589
4 votes
1 answer
488 views

Avoiding virtual thread pinning by moving the code to run on a platform thread

I am migrating my Spring Boot application to virtual threads from the platform ones. Generally, it works fine, no pinning happens. But for some requests, there could be an operation that leads to the ...
Andrey Antipov's user avatar
0 votes
0 answers
57 views

Java 22 build failed: ofVirtual() is unknown [duplicate]

I can not comile a project: grim@main:~/workspace/hl-editor$ mvn [INFO] Scanning for projects... [INFO] [INFO] ----------------------------< hl:hl-editor >---------------------------- [INFO] ...
Grim's user avatar
  • 1,939
1 vote
0 answers
219 views

Java virtual threads: generators / explicit "jump" to another thread

As said in the topic, I wonder if the API of Virtual Threads allow to "jump" straight to another thread we choose. By jumping I mean we at the same time: park the current thread, unpark ...
broot's user avatar
  • 28k
3 votes
2 answers
754 views

Is it necessary to shutdown the executor returned by Executors.newVirtualThreadPerTaskExecutor()?

Project loom introduced a virtual thread executor service Executors.newVirtualThreadPerTaskExecutor() which creates a new Virtual Thread (VT) every time we submit a task. I have a couple of questions ...
Govinda Sakhare's user avatar
0 votes
1 answer
837 views

Logback: availability of MDCs in forks created inside a StructuredTaskScope

When using StructuredTaskScope from JEP 453 in Java 21+ and forking multiple tasks, I'd like to have MDC values propagated to the forks, so that all logs are properly correlated. Extending the example ...
adamw's user avatar
  • 8,576
6 votes
3 answers
629 views

Java 21 structured concurrency, need predictable subtask exception ordering

I'm rather new to parallel code, and I tried to convert some code based on executors to structured concurrency, but I lost an important property that I must somehow keep. Given the following code ...
mdrg's user avatar
  • 3,382
2 votes
1 answer
295 views

What really happens under the hood when a virtual thread is created?

When a virtual thread is created, what happens under the hood? I believe it does the below set of things, can someone explain it in detail? Create a Virtual Thread and Continuation object and assign ...
Govinda Sakhare's user avatar
1 vote
3 answers
997 views

How to call mysql in virtual threads

env mysql-connector-java:8.0.33 java version:jdk21 springboot:3.2.1 virtual thread mode: true connector pool: hikari problem It seems that mysql-connector-java has many synchronized which pinned ...
user7378390's user avatar
0 votes
0 answers
266 views

How to yield the virtual thread?

It seems that mysql-connect-java is not compatible with virtual thread. When i use -Djdk.tracePinnedThreads=full, I found some pinned stack trace. So my question is how to fix this problem? I have try ...
user7378390's user avatar
7 votes
2 answers
1k views

Why do Java 21 virtual threads need less memory than platform threads?

I do understand that platform threads are expensive as it needs more memory and it's prone to CPU context switching. But in case of virtual threads where an unimaginably large number of virtual ...
user1189332's user avatar
  • 1,941
2 votes
0 answers
519 views

Logback thread was blocked with virtual thread envrionment

The detail problem can also see in the github issue: https://github.com/qos-ch/logback/issues/767 I don't know how to solve this problem and i look for your suggestions. Thanks first. I have dump the ...
user7378390's user avatar
7 votes
2 answers
2k views

Should virtual thread die fast?

It' s recommended by JDK developers that virtual threads should never be pooled, because they are really cheap to create and destroy. I am a little confusing about the pooling idea, since pooling ...
benrush's user avatar
  • 307
1 vote
1 answer
140 views

ExecutionCompletionService hangs when used with Project loom

I am trying to use Project Loom to enable invoking a REST server in parallel. In the code snippet below, when I use virtual threads the executorService hangs, but I do not see the same behavior with ...
Hari R's user avatar
  • 133
3 votes
1 answer
3k views

Apache Tomcat with virtual thread

I try to use virtual thread on Apache Tomcat 10.1.16 with this configuration: <Executor name="tomcatThreadPoolVirtual" class="org.apache.catalina.core....
Nicolas's user avatar
  • 41
19 votes
1 answer
5k views

Java 21 built-in HTTP client pins the carrier thread

I'm using Java Corretto 21.0.0.35.1 build 21+35-LTS, and the built-in Java HTTP client to retrieve a response as an InputStream. I'm making parallel requests using virtual threads, and for the most ...
Urb's user avatar
  • 243
1 vote
0 answers
732 views

How virtual thread is parking?

How are virtual threads parked in Project Loom, specifically in scenarios other than LockSupport.park()? I've noticed that LockSupport.park() is used in FutureTask and CompletableFuture, but what ...
hololensen's user avatar
3 votes
0 answers
179 views

What happened to Channels in project Loom?

In State of Loom: part 2, there's a discussion about channels, and that Doug Lea had started working on a synchronous counterpart to Flow, called a Carrier. That was back in May 2020, and Loom is now ...
cw124's user avatar
  • 81
2 votes
1 answer
1k views

Will java's virtual thread be useful for Grpc bidirectional stream application?

We have to create a microservice using spring boot + grpc. We have to use Grpc's bidirectional streaming. So when client connects to the game, the connection is not disconnected until the client ...
PudgeKim's user avatar
  • 153
5 votes
0 answers
2k views

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 ...
chesterbr's user avatar
  • 3,050
4 votes
1 answer
5k views

Synchronize block pinning virtual thread

I am an enthusiast and am wondering about virtual threads. In the docs it says that one of the conditions to pin the thread is in a synchronized block, and in those cases to use a semaphore. Here are ...
Васил Егов's user avatar
0 votes
1 answer
343 views

Helidon Nima + gRPC example

I'm starting a new gRPC project that needs to be production ready early next year. We've been discussing about moving over to Project Loom when it stabilizes. As most of the work is around infra, ...
eof's user avatar
  • 557
4 votes
1 answer
1k views

How is the deprecated Green Threads different from Project Loom?

In the very early Java versions, JVM threads multiplexed to native OS threads. Such threads were called Green Threads. This was deprecated in the very early versions of Java and then every Java thread ...
JavaNovice's user avatar
  • 1,132
0 votes
0 answers
191 views

Why don't my 1_000_000 Virtual Threads print a 1_000_000 outcomes?

I was tinkering with Virtual Threads and made this bit of code: List<Thread> threads = new ArrayList<>(); for(int i = 0; i < 1_000_000; i++){ var thread = ...
Mark Rensen's user avatar
1 vote
2 answers
1k views

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....
Dave Ankin's user avatar
  • 1,251
1 vote
0 answers
70 views

Why does joining a no-op virtual thread in a static initialiser block indefinitely? [duplicate]

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....
michid's user avatar
  • 10.8k
7 votes
1 answer
317 views

How do I safely call CPU-bound code from within a Java19 virtual thread?

We have a Jetty webapp with a custom threadpool backed by Java19 virtual threads. The business logic we run in response to a request is usually IO-bound (e.g. DB queries), so virtual threads have been ...
tsutsu's user avatar
  • 101
0 votes
0 answers
336 views

Why Thread.ofVirtual() and Thread.ofPlatform() named like that?

Why the new methods proposed by JEP 425: Virtual Threads (Preview) are named like that? Given that they return OfVirtual and OfPlatform builder classes, it seems inconsistent with the other usages of ...
user2418306's user avatar
  • 2,382
20 votes
1 answer
12k views

Using Virtual Threads (Project Loom) with Spring WebFlux/Reactor/Reactive libraries

Java Virtual Threads In Java 19 were introduced Virtual Threads JEP-425 as a preview feature. After some investigation of concept of Java Virtual Threads (Project Loom), called sometimes lightweight ...
kerbermeister's user avatar
2 votes
1 answer
545 views

Does a virtual thread wake up in the same carrier thread on which it was blocked?

Is my understanding correct that a virtual thread runs on the same carrier thread throughout its lifetime? If not, then I'm wondering if we'd need to have our instance variables as volatile to have ...
Sanjay's user avatar
  • 8,935
0 votes
1 answer
609 views

Virtual threads slower than single threads

I have a a number of tasks where work can be done in parallel. I have tried this single-threaded and multi-threaded. Code is as follows: private MyTaskResult doTasks( ... ) { try ( var scope = ...
ljm599's user avatar
  • 41
2 votes
1 answer
730 views

How to know which platform thread is carrying the virtual thread?

Is there a way to know which platform thread is carrying the current virtual thread or pin a virtual thread to a platform thread and get its threadlocal in JDK19? I want to reuse some objects in ...
user avatar
4 votes
2 answers
4k views

How does a Java virtual thread know when the thread is waiting?

When a virtual thread is blocked due to synchronized call, it's yielding, so the scheduler will unmount it from related Carrier thread. I was wondering, how does a virtual thread know that it's ...
Amit Erez's user avatar
5 votes
1 answer
904 views

In Loom, can I use virtual threads for Recursive[Action/Task]?

Is it possible to use RecursiveAction, for example, in conjunction with -- instead of the fork/join pool -- a pool of virtual threads (before I attempt a poorly-designed, custom effort)?
HellishHeat's user avatar
  • 2,461
1 vote
2 answers
1k views

Issues in running virtual threads program on intellij with java19

I am trying to run below simple program with virtual threads on my intellij with java19 version selected. Code public class VTSimple { public static void main(String[] args) { Runnable ...
SRJ's user avatar
  • 2,786
2 votes
1 answer
1k views

Java 19 preview, incubator features with Gradle [duplicate]

Java 19 has new features: virtual threads (as preview) and structured concurrency (as incubator). Gradle 7.6 will support Java 19. Given that 7.6-rc-1 is available, how can I try out these new ...
Michael Easter's user avatar
4 votes
1 answer
3k views

Virtual Threads in Tomcat Server

I'm using OpenJDK 19 openjdk 19 2022-09-20 OpenJDK Runtime Environment (build 19+36-2238) OpenJDK 64-Bit Server VM (build 19+36-2238, mixed mode, sharing) And the latest version of Tomcat (10.0.23) ...
areller's user avatar
  • 5,178
3 votes
2 answers
846 views

Minimum concurrency to benefit from JDK19 virtual threads

According to JEP 425, virtual threads can significantly improve application throughput when the number of concurrent tasks is high (more than a few thousand), and the workload is not CPU-bound Why ...
Andrew Parks's user avatar
  • 8,027
0 votes
1 answer
105 views

TLAB in Virtual Thread - Project Loom

How currently TLAB is handling in Virtual Thread introduced by Project Loom in Java? Is TLAB available in virtual threads?
Matrix12's user avatar
  • 486
11 votes
3 answers
5k views

How can I run JDK 19 with Structured Concurrency?

I have edited this to bring things up-to-date wrt the original posting. I want to try the new Project Loom feature defined in: JEP 428: Structured Concurrency (Incubator) I have in my pom.xml <...
Eric Kolotyluk's user avatar
3 votes
4 answers
20k views

Java's Spring Boot vs Python's FastAPI: Threads

I'm a Java Spring boot developer and I develop 3-tier crud applications. I talked to a guy who seemed knowledgeable on the subject, but I didn't get his contact details. He was advocating for Python's ...
Albert Hendriks's user avatar
0 votes
1 answer
434 views

Project Loom: carrier pinning

Why native code leads to carrier pinning? Is it because to switch carrier thread to another virtual thread, it should be parked from Java code? Also, why File I/O pins a carrier thread as well right ...
Rahul's user avatar
  • 1,797
40 votes
5 answers
13k views

What exactly makes Java Virtual Threads better

I am pretty hyped for Project Loom, but there is one thing that I can't fully understand. Most Java servers use thread pools with a certain limit of threads (200, 300 ..), however, you are not limited ...
Borislav Stoilov's user avatar
3 votes
4 answers
2k views

Project loom: Why are virtual threads not the default?

According to the project loom documentation virtual threads behave like normal threads while having almost zero cost and the ability to turn blocking calls into non-blocking ones. If this is true, ...
kqi25755's user avatar
1 vote
3 answers
914 views

May I have Project Loom Clarified?

Brian Goetz got me excited about project Loom and, in order to fully appreciate it, I'll need some clarification on the status quo. My understanding is as follows: Currently, in order to have real ...
HellishHeat's user avatar
  • 2,461
2 votes
1 answer
799 views

Problems trying to use Project Loom/Virtual Threads with OpenJDK 19-loom JAVA

I'm trying to test the virtual threads reference loom project in Java and I'm using the following JDK 19-loom version: package com; import java.util.concurrent.ThreadFactory; public class a { ...
Pablo Sanchez's user avatar
1 vote
1 answer
330 views

Java structured concurrency

Structured concurrency: a simple principle that states that when the flow of execution splits into multiple concurrent flows, they rejoin in the same code block. Source Based on this, let's assume I ...
srock's user avatar
  • 413
2 votes
1 answer
628 views

How Virtual Threads are mapped to Actual thread [closed]

As written, virtual threads are eventually mapped to actual threads. Let's say there are 1 million virtual threads that are created. In a 8 core processor, I assume there will be 8 kernel threads. So, ...
Pakira's user avatar
  • 2,021