Java 20 - From ThreadLocal to ScopedValue with Loom Full Tutorial - JEP Café #16

preview_player
Показать описание
ThreadLocal variables can help you share sensitive information among the different components of an application, without resorting to method calls. They have drawbacks that are now fixed with ScopedValue variables. Understand how ScopedValue are working and how you can use them as an incubator feature in JDK 20.

⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯

0:00 Intro
1:09 Why have ThreadLocal variables been introduced?
2:44 How does ThreadLocal variables work?
4:57 ThreadLocal variables drawbacks: leaking and memory footprint
7:39 How Virtual Threads are changing the need for ThreadLocal
10:10 Introducing the new requirements for ScopedValue
11:02 Creating and using a ScopedValue
13:09 Reading a ScopeValue and dealing with errors
14:17 What is the scope of a ScopedValue?
16:59 Setting several ScopedValue for a task, rebinding a ScopedValue
17:55 Final words and outro

⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯

Tags: #Java #Java17 #Java20 #OpenJDK #JDK #JDK17 #Loom #VritualThreads #JEPCafe #insidejava
Рекомендации по теме
Комментарии
Автор

I hope the world has so much coffee that we can always see you and benefit from your knowledge.🌻

ahuramazda
Автор

It's refreshing to watch someone talking about programming topics in such relaxing manner and surroundings. Feels so different from the majority of other dev channels and conference talks. That's what java is all about - no hurry, steady improvement. Some other java champions also get it (ones like Adam Bien and Sebastian Daschner). And this video makes me want to grab a cup of coffee myself too. Thanks.

michimarz
Автор

Wow, I was not aware this YouTube channel exists. Great content! Thank you for your work!

antimon
Автор

I really like the format of these. I haven't chatted about coding in a coffee shop since before Covid and I miss it!

prdoyle
Автор

Wonderful explanation even non native english users can understand very clearly.

Thanks for that.

thinkbig
Автор

Very illustrative examples around the 16th min. Many thanks!

viewit
Автор

Thanks for the explanation! Looking forward to seeing how this will mix & match with the current MDC objects that are currently used to pass valued for logging frameworks, if they can be used there.
I hadn't thought that ThreadLocal was for security reasons, I had always thought it was to be able to pass values to code that were not direclty in the call chain, hence no parameters prepared to pass them, so, good to know.

ESGreenie
Автор

Loom is cool but what I am most excited about is Valhalla (and Panama second).

xKeray
Автор

Nice talk. I was playing with ScopedValues and I found that the scoped values are not automatically accessible from child threads. Only Child threads from StructuredTaskScope seems to be able to access the ScopedValue of the parent. When i looked at the code, StructuredTaskScope class does seem to capture all ScopedValue of parent and manually pass it to children of StructuredTaskScope. Its probably because the StructuredTaskScope block is guaranteed to end before the scoped value scope ends. Otherwise the scoped value would be accessible even after the ScopedValue block ends.

virajsh
Автор

Is ScopedValue analogous to the Reader Monad in Haskell?

chonh
Автор

I'm curious to know how this is implemented. Does it look at the call stack to determine if the ScopedValue is accessible?

loic.bertrand
Автор

12:30 shouldn't it be "ABC".equals(KEY.get()) instead?

Amejonah
Автор

Nice presentation ! Thought it was InheritableThreadLocal that got copied when making a child thread and not ThreadLocal. Isn’t it ?

huset-solem
Автор

Nice feature to come.
How will a scoped value behave when using a thread pool executor ?
You spawn the tasks from your context but the threads they run on are created out of those bounds.
Should we then care about how an executor work ?

Grimly
Автор

Thanks for the great explanation of both ThreadLocal and ScopedValue APIs. I can't help but notice similarity between ScopedValue APIs and various Mapped Diagnostic Context APIs provided by java logging frameworks like SLF4J/Log4j. I assume that is a deliberate design choice/inspiration here?

khandes
Автор

Kinda confusing - how can this ScopedValue be used across different classes? (as we are using TthreadLocal right now)

AleksandarT
Автор

Hi @Java, first thank you Jose for a great lecture, a question if I may, one of the main reason for a spring developer to use threadLocal is the infamous ObjectMapper with its heavy constructor, so by wrapping the OM in TL var the servlet threads will have it and will not need to re-build it every time, how would you achieve the same effect with a ScopeValue variable? Keep in mind OM can be access from multiple locations during the rest call

roie
Автор

How much blood does this man have in his coffee?

phillable
Автор

10:50 - 11:00 : <insert Rust propaganda here>

Amejonah
Автор

why threadlocal are global variables? As i understand global is static in java but threadlocal not static!

uawinwin