[kcdc 2025] Loom is more than Virtual Threads: Structured Concurrency and Scoped Values

Speaker: Todd Ginsberg

Bluesky: ‪@todd.ginsberg.com‬

For more see the table of contents


Project Loom

Project charter includes;

  • easy to use
  • high throughput
  • lightweight concurrency
  • new programming models on the Java platform

Virtual Threads

  • Platform threads in JVM map to OS threads. Not useful when blocked, memory hungry, limited number by OS, etc
  • Virtual threads have nothing to do with OS. Just memory on heap.
  • When virtual threads have work, mounted to carrier thread.
  • Carrier thread uses OS thread
  • Virtual threads still java.lang.Thread, must lower memory requirements, number limited by heap memory, quick to create, better use of system resources
  • Virtual threads have ids, but not names, by default since you are supposed to use them and then throw away.
  • 2 seconds to create thousands of platform threads. 41 milliseconds to do the same for virtual threads. 368 milliseconds to create a million virtual threads
  • Little’s law: concurrency – arrival rate (aka throughput) * latency. Virtual threads increase thoroughput
  • Do not pool virtual threads. Create, use, expose. You wouldn’t pool other inexpensive objects.

Structured Concurrency

  • API change so still preview in Java 25
  • Suppose have two futures. One that takes 2 seconds and one that takes 4 seconds.
  • Want to kill one when the other fails so not wasting time.
  • While think of as parent/child threads normally, that relationship doesn’t actually exist
  • jps command gives process ids
  • To get thread dump: jcmd <main program process id> Thread.dump_to_file -format=json unstructured.json
  • Goals: promote style of concurrent programming to eliminate common risks, improve concurrency
  • Enforces children don’t outlive parents
  • Explicit relationship between tasks and subtasks, observability is easier, managing work is easier
  • join() – join point waits until all tasks are done and can then interpret results.
  • Create StructuredTaskScope.open() in try with resources which means all or nothing. Whole scope succeeds or fails
  • scope.fork(() -> doWork())
  • scope.join()
  • future.get() to get the answer now that the join is done
  • Can nest scopes

Scoped Values

  • in Java 25 (no longer in preview)
  • ThreadLocal let you set data. Problems: unconstrained mutability (anyone who can read to it can write to it), unbounded lifespan (have to clean up if reusing platform thread), expensive inheritance
  • Scoped values: Immutable, defined lifetime, cheap/free inheritance
  • Ex: static ScopedValue<String> SCOPED. and ScopedValue.where(SCOPED, obj).run(() -> …)
  • Scoped values good for passing data one way. Good when have structured sharing use cases – ex: data many layers way from where you create it
  • Can replace one way ThreadLocal as use case without structured concurrency

My take

Not the point of the talk but I like that he uses Duration.ofMillis() instead of just putting a number. This topic is like pipelines; I needed to hear it a few times from different people for it to click. Given that scope values are in the Java 25 LTS and structured concurrency is not, I was curious how to use scope values alone so nice to hear that.

using the java playground

I’ve started offering using Oracle’s Java Playground for labs when I do half or full day trainings. While not all features can be used in playground. many can. This lets people do most of it if they bring a corporate laptop where they can’t install the matching version.

This time, I decided to put the Java Playground instructions in a blog post since they aren’t specific to the lab and anyone reading this blog post might find it useful.

Getting started – running simple code

Just put the contents of what would go in a main method. For example,

System.out.println("Java");

Working with classes/records

To use classes or records, you declare them before your code and then put the calling code “loose”.

public class Foo {
  
}

new Foo();

Using long code listings

If the code is too long, you’ll get a suggestion to use an IDE as output. All my labs can be done in the playground except for the modules where stated otherwise. You may have to delete some code in order to get later parts of the module to run. (Commenting out does not work as it does not decrease line length)

Features not supported

If you try to run something that isn’t allowed you get:

Your snippet is trying to perform an unauthorized operation!

Examples of unauthorized operations include:

  • thread operations (sleep, platform threads, virtual threads)
  • reading a system property or environment variable
  • reading/writing from a file

PASSED! Jeanne’s Experience Taking the Oracle Cloud Infrastructure Generative AI Professional

Today I took the Oracle Cloud Infrastructure 2025 Generative AI Professional certification and passed with a score of 86%. Passing is 68%. This roughly the score I got on the Foundations exam. Which isn’t surprising. I tend to make the same amount of “careless mistakes” on exams in general with this sort of thing. Even in elementary school. I’d know the material, and write down the wrong answer. Or misread a question.

It’s a 90 minute exam with 50 questions. This is 30 minutes and 10 questions more than the foundations exam. It took me 22 minutes for this exam (and about 10 minutes for the foundation). For both each question was pick one of four multiple choice questions. In many questions one or two were clear distractors. Why did this take twice as long? More questions was part of it. And another was this one had you reading code for some of the questions. Not a lot of code; just 2-6 lines or so. But that takes longer than reading words. Which is probably why the Java 21 cert was a problem with time. That was reading A LOT of code.

Why I took this certification

Oracle is doing a race to certification, where you can take a number of free certifications between now and Halloween. Unlike the Vector cert, which I took solely because it was free, this one I took both because it was free and to learn something. (same for foundations) And I did. Some was new to me and some I used to know and forgot. I especially appreciated learning/reviewing vocabulary and concepts.

What I did:

  • Watched videos and did skills checks from the free course. This was interesting. The skills check questions cover a good amount of the exam materials. I watched it on 2x speed. I also skipped most of the lab videos. I skipped the demos and focused on the concepts because I wasn’t interested in the Oracle Cloud specifics. I did this over two days. There is some repetition in the videos. For example, in context and k shot prompting was in modules 2 and 3. Same slides; different instructor.
  • Watched the video about preparing for the exam. It came with 4 practice questions which were similar to the exam.
  • Did practice exam. This was 50 questions. matching the real exam. The first time thru I got a 68%, which is exactly passing. (I didn’t review my notes at all) It was useful for knowing what I needed to remember. I reviewed 15 answers and then took it again getting an 84%. (I didn’t review them all because I accidentally closed the browser tab.

The exam

All the questions were single answer multiple choice. Like the Vector exam, you had to sign up for a slot in advance. Scheduling wasn’t bad though. I had a choice of any time during the 24 hours of Monday. (and a few 10:30pm or later Sunday night but I am a morning person)

Also, like the Vector exam, i took a picture and showed the computer my id. Then started.

I wrote a separate blog post about the exam engine. I had a few differences form that time though:

  • I had to download software to my machine for Proctorio (“Secure Companion App” and not just the browser plugin this time. I was sure to delete it right after.
  • I had to close my Terminal and Slack this time. While I certainly didn’t use them last time, I didn’t close them. (I don’t have alerts on Slack so it didn’t affect e)
  • Two of the questions had a multiline sentence as answer options that was behind the floating menu bar on the right. The first time, I dragged it was fine. The second time, I accidentally clicked the picture of me (my video) instead of the grab bar. This turned off my video. I clicked to turn it back on immediately and the proctor didn’t comment. There was nowhere good to put the bar though where it didn’t cover something on one question so I moved it a few times.

After the exam

You get a score report on the screen right after submitting and an email right away with the same score. It took a little under an hour to get the second email saying my certview was updated. While Oacle products were used as examples a lot, you only had to actually know about them for a few questions.

What I found most interesting

I like that the questions were a mix on this exam. Some were pure definitions. Some were scenarios where you had to identify a term or algorithm from the description. Some were code where you had to answer a question about it. (luckily the Python code was clear because remember I didn’t watch any of the demos or do the lab).

I also found it interesting how the exams are related. Some of the concepts from other exams were on this one.

How to Study

The learning path is sufficient to take the exam if you go through it carefully. And just like the other AI certs, pay lots of attention ot the sample questions and practice exams! There are only so many ways you can ask certain topics.