ThreadLocal in Java

preview_player
Показать описание
Use ThreadLocal for thread-safety, memory efficiency and for per-thread context storage.

Channel
----------------------------------
Complex concepts explained in short & simple manner. Topics include Java Concurrency, Spring Boot, Microservices, Distributed Systems etc. Feel free to ask any doubts in the comments. Also happy to take requests for new videos.

New video added every weekend.

Popular Videos
----------------------------------
Рекомендации по теме
Комментарии
Автор

thanks for great video!

One question, at 2:55, since all threads just read the same single global SimpleDateFormat obj, however, no thread tries to change it although it is mutable. How can the data integrity issue turn up? Can I still consider SimpleDateFormat obj as thread safe in your example?

Of course, we can ensure the data integrity of SimpleDateFormat obj when necessary by using, ThreadLocal, AtomicReference

SamDLee-votr
Автор

There is no other tutorial on Java Concurrency which is even half good as yours. Thank you Sir for making these videos. Keep it coming.

vishalsrane
Автор

This is guy is one of the most inspiring geniuses I've ever met

dk
Автор

After watching your videos, I removed all AsyncTask from my android Java code and introduced Java concurrency. Your videos about multithreading are awesome.

SouravBagchigoogleplus
Автор

Good Job in a span of 2 day I watched multiple videos and I can tell you your content is enriching for the experienced professionals as well.
Keep it up.

cpsarathe
Автор

Seeing this after 4 years -it is a gem ! , I have gone through several tutorials, I understand and forgot over time, the way you are explaining wont let you forget even if you want to be :) , great work and god bless

kishorsundar
Автор

2:00
ThreadLocal creates a separate copy of the object for each thread.
To avoid multiple threads accessing the same object which isn’t thread safe. Multiple threads can access the same object with locks but that decreases performance. This also avoids each runnable task submitted to a thread pool creating its own object because we can have thousands of runnable
5:10 implementation
6:19 can be used to store variable like user, which needs to be passed from one service to the next. Instead of passing it as a param from one thread to the next, we can use threadlocal static variable and set it when a request comes in. So this is setting a context for a thread.
Spring uses the concept of context in these examples 8:50

mostinho
Автор

You have, hands down, the best content on Java concurrency, of all the resources out there. Really really appreciate the effort you put into you videos, thank you so much for making all these concepts intuitive and easy to ingest.

navneet
Автор

Notes for myself:
Threadlocal.initialize() --> sets the value of threadlocal, it is invoked automatically.
Threadlocal.get() --> used to fetch value from ThreadLocal
Threadlocal.set() --> needs to be called manually in order to set some value in ThreadLocal

Task is different from thread. 3:29 10 threads from Threadpool can do 1000 different tasks

avijitsharma
Автор

number of likes are misproportioned to the quality content you have provided. great job

Kasas
Автор

Best way to explain is what was problem case, what is use of that component or rearm and then explain use of that teram....
Awesome explanation bro

MHK
Автор

For some reason the video thumbnail shows the video is 20mins. Thanks for the great content.
For viewers: Do write a clean up method (remove()). I forgot it once and it created a huge memory leak!!

shashidhar
Автор

Excellent explantation. In your videos, you are explaining very difficult concepts like Java concurrency to be understandable easily. Thanks for the effort. I will share this to whoever needed. Why there are no videos from you recently. Keep doing your good to work.

saidivinity
Автор

very nice video ! In the second user case, “services” is little misleading, as people would think each service is running on it is own server, “handler” might be better word.

diwu
Автор

Its great. Short and sweet. Straight to the point! Thank you

cslxxwilliam
Автор

Absolutely brilliant. Crystal clear explanation. Thanks man.

shubhamchandra
Автор

Boss you nailed it. Your way of explaining complex things makes it very easy to understand. Thanks and keep posting more videos :)

ganeshpathak
Автор

I'm from China, your video is very awesome!Keep going!

gefeizhu
Автор

I think your good expertise in concurrency you are doing great job

harivignesh
Автор

Crisp and precise explanation of concepts as always.
Below are my observations and queries, please clarify.
- Use Case #1 : I understand that SDF(SimpleDateFormat) was used as example to explain the concept of ThreadLocal but for practical situations, is FastDateParser class a good alternative to SDF, which is a thread safe version of SDF. Correct me if I m missing anything here.
- Use Case #2 : In the start of the use case #2, there was a mention of usage of HashMap to store the use id across the threads but when presentation extended instead of
TheadLocal <HashMap<User>>, only TheadLocal<User> was considered; was it for simplicity of the problem ? If not, I believe TheadLocal<HashMap<User>> would still be required for the scenario mentioned.

cseshivaprasad
welcome to shbcf.ru