It's time for #JavaTuesdayThread!

You know that JDK 19 will be released in 2 months on Sept. 20th. It will bring some major changes to the JDK. Project #Loom is one of those HUGE changes I want to talk about a little bit more. #Java #OpenJDK
JEP 425 introduces Virtual Threads. The most interesting thing is that the JDK was reworked to make it possible to block both platform and virtual threads in different ways.
While thread blocking methods will put on pause the whole platform thread, the virtual thread blocking wouldn't block its underlying carrier thread so it can pick up the segment of another virtual thread to execute.
There are a lot of blocking methods in JDK. A simple PrintStream::println will make a scheduler park a virtual thread until it is done. So, eventually, a virtual thread will be executed on multiple carrier threads, here's how to check it:
The result would be pretty verbose:
Not only I/O operation make a scheduler park a virtual thread. Ordinary Thread::sleep was also reworked to make a distinction between a platform thread and a virtual one. So, every method inside the JDK that was causing a thread to block will know how to treat a virtual thread.
Worth to say that, when a virtual thread is parked, the whole execution stack of it is moved to a heap if it has more things to do after blocking method completion. So, it'll be moved back once a virtual thread can proceed (unparked and assigned to a carrier thread).
The most interesting park of virtual threads is the Continuation. The concept is very similar to Python's generators (and coroutines before v3.6).
A virtual thread holds an instance of the continuation that has a yield point and can be started or continued (through Continuation::run method) by the external subsystem.
So, it appears to be that the execution of a virtual thread is the execution of the continuation object. A virtual thread blocking makes the continuation yield.
Note: Please be aware that as of now, Continuations API isn't a public one. However, it may change in the future.
You see, virtual threads will be a very hot topic and we'll hear more talks and will see more experiments soon enough.
BONUS! The last time I've written about Loom I made an experiment by launching 2M virtual threads running HTTP requests, it took me quite some time to finish. But this time I decided to reduce the scope and see where's the limit and how the program will fail.
It took around 12s to launch 10M virtual threads, and 30s to launch 15M. But then I just ran out of RAM, so the experiment failed at around 16M virtual threads. The numbers are literally crazy compared to the 4073 platform threads that the JVM can occupy before it crashed.
If you want to learn more about virtual threads, watch @JosePaumard's #JEPCafe or attend one of his workshops, it's definitely worth it!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Denis Makogon

Denis Makogon Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @denis_makogon

Mar 9
This is the first war in a modern world where we have more than just one physical frontier. As Ukrainian IT community we started another one - virtual. I’ll explain you how it works here in #Ukraine and abroad
[thread]:
#Ukraine has more than 160K IT specialists: hardware engineers, cloud engineers, software engineers, devops, architects, QA, etc.
We do have IT security folks known as Ukrainian Cyber Alliance (@UCA_ruhate_). They were the first ones who attacked #Russia’s IT infrastructure.
Read 11 tweets
Mar 8
Yesterday I explained you how a war in Ukraine will affect Europe in terms of food.

Today I will explain you how it will affect your comfort [thread]:
I’d you didn’t know - Ukraine average per hour rate is pretty low comparing to European. That’s why we do lots of outsourcing businesses. We have thousands of smart engineers who do work for US/EU businesses.
VM, Mercedes-Daimler, BMW uses Ukraine as an R&D centers.
Read 8 tweets
Aug 25, 2021
The reason why I love and hate #Kubernetes is it actually good platform to host scalable apps. But the road from developing the app to making it scalable is so painful. Here are few-reasons-why-thread:
#Kubernetes in its bare configuration can only host containers and let you talk to them. Include config maps, volumes, RBAC, etc.
If you ever wanted to scale your app on #Kubernetes you probably heard of MetricsServer - it can collect standard metrics like CPU and RAM of every pod/container.

It’s not a part of #k8s distribution - you need to install it separately.
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(