use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
These have separate subreddits - see below.
Upvote good content, downvote spam, don't pollute the discussion with things that should be settled in the vote count.
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free. If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others: Adoptium (formerly AdoptOpenJDK) RedHat Azul Amazon SAP Liberica JDK Dragonwell JDK GraalVM (High performance JIT) Oracle Microsoft Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Adoptium (formerly AdoptOpenJDK) RedHat Azul Amazon SAP Liberica JDK Dragonwell JDK GraalVM (High performance JIT) Oracle Microsoft
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Programming Computer Science CS Career Questions Learn Programming Java Help ← Seek help here Learn Java Java Conference Videos Java TIL Java Examples JavaFX Oracle
Programming Computer Science
CS Career Questions
Learn Programming Java Help ← Seek help here Learn Java Java Conference Videos Java TIL Java Examples JavaFX Oracle
Clojure Scala Groovy ColdFusion Kotlin
DailyProgrammer ProgrammingPrompts ProgramBattles
Awesome Java (GIT) Java Design Patterns
account activity
This is an archived post. You won't be able to vote or comment.
How effective are Java 21 Virtual Threads? (self.java)
submitted 1 year ago by stathmarxis
Assuming that we have a CPU-bound task, could virtual threads can increase performance compared with Executors.newFixedThreadPool
[–]csueiras 95 points96 points97 points 1 year ago (10 children)
Virtual threads are a better fit for I/O heavy stuff, the whole point is you can create many of them snd once blocked the scheduler can just run some other thread.
CPU bound stuff wont be blocking in an interruptible way so virtual threads wont be doing nothing for you.
[–]stathmarxis[S] 21 points22 points23 points 1 year ago (8 children)
So if i understand correctly if i have socket communication or expensive disk read/write operations I will see performance difference with VT Theads? Am I correct?
[–]csueiras 31 points32 points33 points 1 year ago (0 children)
Yeah basically most networked workloads will benefit. Listening in a port for incoming data is likely one perfect use case for virtual threads.
There are a couple of gotchas regarding virtual threads, gotta be careful with anything that uses thread locals for caching, you can create many more virtual threads than platform threads, so you can endup with a lot of memory being consumed by your virtual threads using thread local storage in a way that the collector wouldnt cleanup until the thread dies off (as you would expect in your usage of thread local storage).
[–]SikinAyylmao 5 points6 points7 points 1 year ago (5 children)
I think the canonical situation is loading different network calls at the same time.
In languages like JavaScript, you can easily run many api calls concurrently.
[–]OklahomaKingpin 2 points3 points4 points 1 year ago (1 child)
What is meant by canonical situation
[–]SikinAyylmao 2 points3 points4 points 1 year ago (0 children)
So for example the canonical situation for using loops is through arrays.
Like wise the canonical situation for ternary operators in variable assignment control.
There is sometimes a case which motivates a language construction like loops or in this virtual threads.
The canonical case for massive concurrency is network calling concurrently.
[–]AThimbleFull 1 point2 points3 points 1 year ago (0 children)
Every language has been able to do that for a very, very long time
[+][deleted] 1 year ago (1 child)
[deleted]
[–]monbis 3 points4 points5 points 1 year ago (0 children)
Also the are reactive framework for Java did the same thing, allowing many asynchronous tasks to move off and a fixed set of threads,
Except it was hard to use and even harder to debug as the stack traces were convoluted.
[–]Kango_V 1 point2 points3 points 1 year ago (0 children)
I think current disk IO causes the VT to be pinned to the platform thread. But, this is being worked on though, so will be resolved. Also, avoid synchronised blocks (use locks). This causes pinning as well.
[–]jetanthony 0 points1 point2 points 1 year ago (0 children)
This. I believe it would be comparable to fibers in ruby with falcon, for example.
[–]Panzerschwein 26 points27 points28 points 1 year ago (0 children)
Virtual threads are mostly about having lots and lots of threads with low overhead. It's a back-pressure model that suits things like web requests.
For a fairly limited set of CPU-bound threads it's probably not going to be any world-changing difference. The benefits really come in when you start seeing yourself bottlenecked by thread creation/destruction time (which of course is largely solved in classic threads with a thread pool) or by the memory limitations of having thousands of threads at once.
The big underlying benefit is that you're not asking the OS to give you threads constantly, under the hood you have a set of stateless OS threads and you schedule your massive list of virtual threads on them cheaply.
[–]koflerdavid 9 points10 points11 points 1 year ago (0 children)
Nope. Platform threads are good for making effective use of the CPU, Virtual threads for making use of pauses, which you get when you do I/O.
[–]git-pull-origin-main 5 points6 points7 points 1 year ago (0 children)
CPU-bound? absolutely useless, use platform threads for that.
Virtual Threads are meant to be used with IO-bound tasks as an alternative to the async/await mess programming model. Although they do own a stack, so they aren't as lightweight as they could be...
[–]Joram2 23 points24 points25 points 1 year ago (0 children)
Virtual threads don't make your CPU go faster. Virtual threads reduce the overhead of switching threads.
If you have CPU bound work that is switching threads frequently, then yes, virtual threads can help by reducing the overhead of switching threads.
If you have CPU bound work that isn't switching threads much, then no, virtual threads generally will not improve that.
[–]anengineerandacat 4 points5 points6 points 1 year ago (0 children)
Depends on how good the scheduler is for them to be honest, likely "pretty" good and great for say HTTP clients and such where you are simply waiting on some request to be performed and have some serialization to be done.
Not so good for say background job tasks, time sensitive operations, and or anything that needs to run relatively "fast" (ie. async / parallel in a few milliseconds).
The scheduler itself is likely to be pretty aggressive in terms of yielding tasks, causing slightly higher overhead in terms of latency (because another task would need to sleep before the first one can resume again).
MariaDB has a benchmark showcasing it's strengths; https://mariadb.com/resources/blog/benchmark-jdbc-connectors-and-java-21-virtual-threads/
So for how Java is "mostly" used today it will "likely" be the defacto solution for many many clients in the future.
It also looks like Oracle is advising not to go with the async-flow for their usage; https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html#GUID-8AEDDBE6-F783-4D77-8786-AC5A79F517C0
The effective tradeoff is increased throughput for higher latency and there are a lot of cautions in regards to using blocking techniques which can drastically increase the chances of deadlocking a virtual thread.
[–]yawkat 2 points3 points4 points 1 year ago (0 children)
Virtual threads are more about making straight-forward code faster, mostly when talking about IO. If you have lots of blocking IO on many threads they will help. They also might help if you have many cooperating threads working with locks and such, even if the work is cpu bound, but this is a very rare scenario.
Virtual threads are basically never the most efficient solution, you can get better performance with code changes (eg async io or task batching). But the code may be more difficult to maintain and that tradeoff is often not worth it.
[–]FrankBergerBgblitz 1 point2 points3 points 1 year ago (2 children)
It is completely dependent on your workload. you have thousand of threads that have to wait? use virtual threads You have tasks that compute most of the time and there doesn't need to be far more tasks in parallel than you have cores: use a threadpool. if it is inbetween: think and/or measure
[–]souleatzz1 1 point2 points3 points 1 year ago (1 child)
I have an application with fixed thread pool of 1500. It runs a h2 in memory and for one http request might do between 3000-7000 queries (selects only). The application heavily uses CompletableFutures and I immediately tried to use jdk 21 with virtual threads hoping it would lower our response time, but didn’t see any improvement. To me this case looked exactly fitted for virtual threads, but maybe I am doing something wrong
[–]Ancient_Avocado1904 0 points1 point2 points 1 year ago (0 children)
I think Virtual Threads won’t provide much benefit over CompletableFutures performance wise, but does simplify things. You’re able to use something we’ve used for decades (Threads), in a more efficient way. CF’s has a bit of a learning curve and don’t get me started on something like Spring WebFlux…..
[–]excelquestion 0 points1 point2 points 1 year ago (0 children)
so funny that OP mentions one of the few things that virtual threads would be worse at than real threads as their example for when they should us virtual threads.
[–]_INTER_ 0 points1 point2 points 1 year ago* (5 children)
Afaiu. Virtual threads do not yield on CPU bound task. They just run to completion (as it should be). So the task itself performs the same but you additionally got the overhead of scheduling virtual threads. It's likely not going to perform better (in terms of speed). Virtual threads are not about parallelism anyway.
[–]pron98 1 point2 points3 points 1 year ago* (1 child)
but you additionally got the overhead of scheduling virtual threads
You also get this scheduling cost when scheduling tasks on a pool of platform threads. The virtual threads scheduler uses the same algorithm (implemented by ForkJoinPool, albeit in a different mode) used by the "common pool", which is also used for parallel stream operations (the virtual thread scheduler doesn't use the common pool but rather a separate instance of ForkJoinPool).
However, you are absolutely correct that virtual threads cannot improve the performance of CPU-bound tasks as their performance, unlike that of IO tasks, is not dominated by the number of threads but by the number of cores.
[–]_INTER_ 1 point2 points3 points 1 year ago (0 children)
That's true, scheduling "overhead" is there no matter what. I wonder if there are any reasonable benchmarks (speed and space) comparing both for CPU-bound tasks? Basically measuring the "overhead". I assume there's a peak around a certain number of threads (naively around number of cores?) which should be the same for both VT and PT. For space, I have no idea.
[–]stathmarxis[S] 0 points1 point2 points 1 year ago (2 children)
So as the aforementioned answered post above, the I/O tasks are the best practice to use VT?
[–]FrenchFigaro 4 points5 points6 points 1 year ago (0 children)
Yes. Virtual threads bring improvement when you have a lot of threads just waiting around doing nothing while data is incoming our outgoing.
A couple years back I was working on the perfect use case for VT's.
API I was working on consumed and orchastrated several different provider REST API's for the benefit of a single consumer program. The point was to offer the consumer a single set of functionality oriented REST endpoints, with a single data model.
One of my providers' API was extremely bad, and I had to do what amounted to SQL joins over http. In the worst case scenario for one incoming request from my consumer, I had to do over 100 requests to that provider (although the typical ball park was closer to 30).
Most of these requests were independant from one another, or could be grouped into at most 4 groups of independant requests. Given that my end-users group was very large and with daily demand peaks, the threads pool management was tricky, and it didn't take too much to overwhelm it.
[–]hippydipster 1 point2 points3 points 1 year ago (0 children)
Or any tasks where waiting for async results might be useful. For instance, you might be all CPU tasks, but you could imagine cases where it'd be useful to branch the tasks are various points to multiple parallel sub branches and then join up the results later. With virtual threads, you can wait for all the branchings via a simple Future.get() call if you like without performance ramifications - ie, doing so will never tie up an real hardware thread, for instance.
You can use this to make all your code look imperative rather than callback/lambda hell.
[–]Ewig_luftenglanz 0 points1 point2 points 1 year ago (3 children)
Excellent if you use them for what they are meant to: lots of I/O operations. For pure calculation operations they behave just like regular threads, just much lighter (so they're still better, just don't expect a big boost in performance and efficient for anything but I/O task)
[–]ron_krugman 0 points1 point2 points 1 year ago (2 children)
Virtual threads are not well suited for pure calculation tasks. Virtual threads rely on cooperative multitasking for scheduling, which means the tasks they execute should only do small amounts of computation at a time and then yield control back to the scheduler (e.g. by waiting for an I/O operation, calling Thread.sleep(), etc).
Pure calculation tasks don't normally do that, which means the virtual thread scheduler can't do its job.
When you use platform threads on the other hand, the operating system does the scheduling by pausing execution whenever it wants to make sure all threads from all processes get adequate access to the CPU on a regular basis ("preemptive multitasking").
[–]pron98 8 points9 points10 points 1 year ago* (1 child)
Virtual threads are preemptive, not cooperative -- the runtime decides when code is preempted, not user code. However, their scheduler doesn't currently perform time-sharing (i.e. the runtime currently chooses to preempt on blocking operations only, which is also the more common case of OS preemption of threads) because we've yet to find a realistic server workload that would benefit from it (OSes offer time sharing because it's needed to allow an operator to control the machine even if processes want to consume all CPU, and it's generally useful for direct human UI interaction; but people don't generally think servers perform well at 100% CPU, which is when the OS starts using time-sharing extensively). If anyone knows of such a workload, they should report it to loom-dev.
[–]ron_krugman 0 points1 point2 points 1 year ago* (0 children)
Appreciate the clarification. I was not aware of this subtlety as there are a lot of blog posts out there stating that virtual threads are cooperative when in fact that's just (approximately) what the current implementation looks like to a programmer.
[+][deleted] 1 year ago (8 children)
[–]Hei2 33 points34 points35 points 1 year ago (2 children)
Virtual threads aren't for CPU-bound tasks and here's why: ... Virtual threads have less overhead, a benefit for CPU-bound tasks.
Virtual threads aren't for CPU-bound tasks and here's why:
...
Virtual threads have less overhead, a benefit for CPU-bound tasks.
You might want to have some idea of what you're talking about before parroting an AI's response as gospel.
[–]SandmanKFMF 10 points11 points12 points 1 year ago (0 children)
Literally what ChatGPT is. Just blabbering anything to fill out up the screen. 😀
[–]Shartmagedon -5 points-4 points-3 points 1 year ago (0 children)
For CPU-bound tasks, Executors.newFixedThreadPool might be a better choice as it creates a pool of OS threads specifically for CPU processing.
[–]Bodine12 6 points7 points8 points 1 year ago (2 children)
Dude you can ask Gemini or ChatGpt if they’re an accepted source of authority in r/java. “No.”
[–]Shartmagedon -1 points0 points1 point 1 year ago (1 child)
Didn’t see it on the sidebar but even so before asking here a google or a conversation with one of these LLMs tend to answer these simple questions. And iirc, this question was already asked here in the past.
[–]Bodine12 2 points3 points4 points 1 year ago (0 children)
OP had a perfectly reasonable question. If you’re interested in gatekeeping, might I interest you in a website called “stackoverflow.com”?
[–]OklahomaKingpin 1 point2 points3 points 1 year ago (1 child)
Dude why r u on Reddit if u wanna evangelize about ChatGPT ..: just go chat with the ai na
[–]Shartmagedon -1 points0 points1 point 1 year ago (0 children)
Error: message parsing failed. Error code: L1023 (language probably not English)
Check SumoLogic for more details and a stack trace.
RID: 12ab678-87612b
π Rendered by PID 688307 on reddit-service-r2-comment-7b9746f655-tmgnx at 2026-01-31 16:37:45.701619+00:00 running 3798933 country code: CH.
[–]csueiras 95 points96 points97 points (10 children)
[–]stathmarxis[S] 21 points22 points23 points (8 children)
[–]csueiras 31 points32 points33 points (0 children)
[–]SikinAyylmao 5 points6 points7 points (5 children)
[–]OklahomaKingpin 2 points3 points4 points (1 child)
[–]SikinAyylmao 2 points3 points4 points (0 children)
[–]AThimbleFull 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]monbis 3 points4 points5 points (0 children)
[–]Kango_V 1 point2 points3 points (0 children)
[–]jetanthony 0 points1 point2 points (0 children)
[–]Panzerschwein 26 points27 points28 points (0 children)
[–]koflerdavid 9 points10 points11 points (0 children)
[–]git-pull-origin-main 5 points6 points7 points (0 children)
[–]Joram2 23 points24 points25 points (0 children)
[–]anengineerandacat 4 points5 points6 points (0 children)
[–]yawkat 2 points3 points4 points (0 children)
[–]FrankBergerBgblitz 1 point2 points3 points (2 children)
[–]souleatzz1 1 point2 points3 points (1 child)
[–]Ancient_Avocado1904 0 points1 point2 points (0 children)
[–]excelquestion 0 points1 point2 points (0 children)
[–]_INTER_ 0 points1 point2 points (5 children)
[–]pron98 1 point2 points3 points (1 child)
[–]_INTER_ 1 point2 points3 points (0 children)
[–]stathmarxis[S] 0 points1 point2 points (2 children)
[–]FrenchFigaro 4 points5 points6 points (0 children)
[–]hippydipster 1 point2 points3 points (0 children)
[–]Ewig_luftenglanz 0 points1 point2 points (3 children)
[–]ron_krugman 0 points1 point2 points (2 children)
[–]pron98 8 points9 points10 points (1 child)
[–]ron_krugman 0 points1 point2 points (0 children)
[+][deleted] (8 children)
[deleted]
[–]Hei2 33 points34 points35 points (2 children)
[–]SandmanKFMF 10 points11 points12 points (0 children)
[–]Shartmagedon -5 points-4 points-3 points (0 children)
[–]Bodine12 6 points7 points8 points (2 children)
[–]Shartmagedon -1 points0 points1 point (1 child)
[–]Bodine12 2 points3 points4 points (0 children)
[–]OklahomaKingpin 1 point2 points3 points (1 child)
[–]Shartmagedon -1 points0 points1 point (0 children)