Java ThreadLocal

  Рет қаралды 39,020

Jakob Jenkov

Jakob Jenkov

Күн бұрын

Пікірлер: 85
@wizzard211
@wizzard211 2 жыл бұрын
Guys don't get overwhelmed, its a simple Map for threads. Each thread has it's own key and value.
@shankar7435
@shankar7435 7 ай бұрын
I do agree but it's a luxury to have it and use it without doing all that additional map work. Loved this feature in language. ❤❤❤
@av98
@av98 3 жыл бұрын
You have created one of the best tutorial for multi threading.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you very much! :-) Glad it is helpful!
@shankar7435
@shankar7435 7 ай бұрын
First time i ever felt someone giving correct portion of details for a concept in java using reasonable and correct language usage. ❤❤❤
@JakobJenkov
@JakobJenkov 6 ай бұрын
Thank you !! 😊
@shubhamagarwal1434
@shubhamagarwal1434 8 ай бұрын
God of Concurency..i have bene flowing you since my 2014 when you used to write blog post only...by going through your post i attend interview like a LION when they ask mutithreading qns.......Thanks a Lot form 10+ yrs exp guy from BLR,India.
@JakobJenkov
@JakobJenkov 7 ай бұрын
Thanks :-)
@shobhanksharma65
@shobhanksharma65 3 жыл бұрын
When I saw name 'Jakob Jenkov', I immediately remembered a lot of your blogs on your website and I was sure your videos won't be let down as well. And as expected these are great!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks - I am glad I did not disappoint you :-D
@tousif161
@tousif161 2 жыл бұрын
The best tutorial on multithreading. Thanks for making my life easy - was struggling to understand ThreadLocal concept.
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are welcome! :-) Great to know my tutorial was helpful to you! :-)
@gparashar4u
@gparashar4u 4 жыл бұрын
Great. Clear the of confusion around using ThreadLocal in the thread pool. Thanks.
@JakobJenkov
@JakobJenkov 4 жыл бұрын
You are welcome! :-)
@farhaankazi7134
@farhaankazi7134 2 жыл бұрын
Thanks, Jenkov, I really appreciate your work. Finally, I understood how the hell Thread Local work without confusion. I read your article. I liked it and that was enough, but it also inspired me to see your vlog and I also saw it. Both of them are really best and worth spending time on both of them
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you very much for your kind words! :-) I am happy that my tutorials are helpful to you! :-)
@akshukla04
@akshukla04 4 жыл бұрын
Thanks Jakob for posting these videos. I have been following your articles for over 4-5 years now. and Its nice to see you are posting videos on KZbin as well. Java Concurrency has been a painful topic for me. I hope to see more videos from you on Java Concurrency. Thanks Again !!!!
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Hi Akhilesh, thank you for your feedback! :-) I plan to post several more videos within the Java Concurrency topic over the coming months. Hopefully you will find them useful too :-)
@abhishekbaghel
@abhishekbaghel 4 жыл бұрын
good to see your youtube channel. I have learned a lot from your blogs. thanks for creating your youtube channel. looking forward to your upcoming video
@JakobJenkov
@JakobJenkov 4 жыл бұрын
You are welcome :-)
@maluginp
@maluginp 4 жыл бұрын
Thanks, it's awesome guide to multithreading in Java.
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thank you - it's still "under development" :-)
@Golipillas
@Golipillas 3 жыл бұрын
Not a single dislike, well deserved, awesome content! 😊
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you very much! :-)
@developerscentre
@developerscentre 9 ай бұрын
Best channel for any Java related concepts! Please keep coming with more such contents. 🙂
@JakobJenkov
@JakobJenkov 8 ай бұрын
Thank you very much! I've got a video on the Java ForkJoinPool coming out next week!
@mostinho7
@mostinho7 3 жыл бұрын
Thanks for great video Todo: take notes ThreadLocal in a thread pool will let tasks share variables stored in the threadlocal if the tasks are run by the same threads, this may not be what you want Inheritable thread local allow child threads to share values, normal thread local is per thread
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! :-)
@manOfPlanetEarth
@manOfPlanetEarth 2 жыл бұрын
@@JakobJenkov wow! nice issue!:) Bit of advice: when it'not clear which thread prints null, add pls a string, it's more illustrative. Like: Sout(some_null_var); -> Sout("Thread 1: " + some_null_var);
@isaiassalles1180
@isaiassalles1180 2 жыл бұрын
Dude, I love the content you have in your website and your videos make things even better
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you very much! ... working on a new video, by the way. It will probably be out next week :-)
@namigtahmazli7870
@namigtahmazli7870 2 жыл бұрын
Such a valuable resource. Thank you very much.
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are welcome! :-)
@alanbidu1
@alanbidu1 3 жыл бұрын
Thank you for sharing knowledge.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome :-)
@SoeaOu
@SoeaOu 3 жыл бұрын
thank you for the excellent videos in high quality
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome ! Glad you like them! :-)
@oliveryt7168
@oliveryt7168 2 жыл бұрын
Well done with the presentation and explanation!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you 😊
@kafychannel
@kafychannel Жыл бұрын
Great tutorial! Thanks a lot. I also read it in text version, love it :)))
@JakobJenkov
@JakobJenkov Жыл бұрын
Great to hear! :-) I am happy my tutorials are helpful!
@ghettoteacher8713
@ghettoteacher8713 4 жыл бұрын
Hi there! I have recently finished a grad scheme as a software engineer and find your articles really helpful! Not sure if you’ve heard of the Disruptor library (from LMAX) but it would be cool to see you eventually teach that since it’s pretty cool the way they incorporate mechanical sympathy! Thanks and please do continue creating vids !
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thank you very much for your kind words about my tutorials! :-) I am aware of the Disruptor, but it's only one of many ways to achieve high performance samethreaded / singlethreaded style architectures. I may be getting to those later in this tutorial series. I have already discussed many of them on my tutorial website.
@ashutoshkumarsingh1
@ashutoshkumarsingh1 3 жыл бұрын
U r awesome man👍🏻
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you ! :-)
@antonhen23
@antonhen23 4 жыл бұрын
Great lesson!
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thanks :-)
@pubgbattleground9208
@pubgbattleground9208 3 жыл бұрын
nice video. good work
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you! :-)
@pawelchrzanowski8
@pawelchrzanowski8 2 жыл бұрын
very good content
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks, Pawel :-)
@mr.swapyyc
@mr.swapyyc 2 жыл бұрын
Helpful!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks! :-)
@RaviNagubandi
@RaviNagubandi 3 жыл бұрын
Thanks Jakob for awesome content. Can you share the code snippets in your github repository?
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Eventually I will - but right now they are not shared. It's a time issue... so much to do - so little time! :-)
@menchomenchev8973
@menchomenchev8973 2 жыл бұрын
Hello Jakob. Very well presented. There is a missing piece, however, why does the Threadlocal class is capable of keeping a single value internally per thread that accesses it? and why would we want to to use the class (as a container) in the first place?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
ThreadLocal is typically used to create thread level singletons.
@menchomenchev8973
@menchomenchev8973 2 жыл бұрын
@@JakobJenkov Thank you, appreciate it!
@varunupadhyay3836
@varunupadhyay3836 3 жыл бұрын
The second thread can actually end up seeing the value being set by thread one if we don't include the sleep as part of thread 2. Not sure if its some form of reference leakage or its necessary to remove the value as part of same thread.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Two different threads setting variables on a ThreadLocal should always only see the value they set themselves. They should not be able to see each other's values set on a ThreadLocal.
@almonyplony1280
@almonyplony1280 4 жыл бұрын
To be honest, I didn't understand what is the difference between this ThreadLocal and a regular local variable? What can this ThreadLocal solve for me, that a regular local variable can't?
@JakobJenkov
@JakobJenkov 4 жыл бұрын
If two threads use the same ThreadLocal instance, they can store their own value inside it. They don't see each other's values. The values stored by a thread in a ThreadLocal is "local" to the thread that stored it. If you just used a standard shared value instead, all threads would see the same variable value - the last stored value by any thread (provided access to the variable is properly synchronized - or the variable is volatile) - not the value stored by the thread reading the variable (as is the case with ThreadLocal).
@muammaryusuf7083
@muammaryusuf7083 3 жыл бұрын
@@JakobJenkov, why not user private local variable? is problem solve for syncronize? so... how if we want share same variable for two thread? for example we have shareObject1, i want share those with Thread1 and Thread2? howto solve using ThreadLocal?
@LuneAgent
@LuneAgent 3 жыл бұрын
First thing that comes to mind: you can use ThreadLocal to count the number of tasks that each thread has completed. You can have just one variable field that will show different numbers for each thread in the pool when accessed from corresponding threads.
@Manuel-oe4gv
@Manuel-oe4gv Жыл бұрын
@@LuneAgent You can have a local variable inside the thread doing the same thing right?
@ahmeedev
@ahmeedev 3 жыл бұрын
Thanks😍
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! :-)
@MissBlurryFace
@MissBlurryFace Жыл бұрын
At 13:03 you are mentioning that child thread does not know about the threadLocal but only inheritableThreadLocal. This part is not clear to me? Both the threadLocals have been set in the parent thread yet child only sees the inheritableLocalThread. . Btw thank you so much for these videos.
@dontwanna6759
@dontwanna6759 4 жыл бұрын
hey jacob i love your java tutorial i am just finishing with core java concepts can you share beginner friendly projects
@JakobJenkov
@JakobJenkov 4 жыл бұрын
I have more beginner friendly tutorials on my tutorial website, here: tutorials.jenkov.com/
@muammaryusuf7083
@muammaryusuf7083 3 жыл бұрын
If only for save and get data for locally thread, why not use local variable instead?, can you tell me when ThreadLocal usefull usage?
@JakobJenkov
@JakobJenkov 3 жыл бұрын
If you have an object that is being called by more than one thread, and you need to keep some state in the object between calls, and you don't want that state shared between the threads, then using a ThreadLocal instead of a normal member variable (AKA field) can solve the problem.
@muammaryusuf7083
@muammaryusuf7083 3 жыл бұрын
@@JakobJenkov , great... thanks very much....
@threadRunnable
@threadRunnable 9 ай бұрын
why to use threadlocal if we have local variable to use?
@JakobJenkov
@JakobJenkov 9 ай бұрын
ThreadLocal is not for local variables, but for member variables in objects that are shared among threads - but which should be "local" to each thread.
@mehedihassan5184
@mehedihassan5184 2 жыл бұрын
Best
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks 😊
@liu-zl9df
@liu-zl9df 3 жыл бұрын
good man
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks :-)
@ersachin1204
@ersachin1204 4 жыл бұрын
sir how to create KZbin downloader in android studio ?
@JakobJenkov
@JakobJenkov 4 жыл бұрын
I don't know, unfortunately!
@subashsakthivels8808
@subashsakthivels8808 2 жыл бұрын
Good video, but it's make me sleep
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you! ... sad my tone of voice makes you sleepy :-) ... I am trying not to speak too fast, so as many as possible can keep up. By the way, you can play the video in 1.25 or 1.5 x normal speed - maybe that helps?
@manOfPlanetEarth
@manOfPlanetEarth 2 жыл бұрын
@@JakobJenkov :)) Now i am playing at 0.75x speed and with subtitles in order to think over what was said.
@oliveryt7168
@oliveryt7168 2 жыл бұрын
I actually like the way he talks... like a normal human being...
Race Conditions in Java Multithreading
22:39
Jakob Jenkov
Рет қаралды 35 М.
Thread Signaling in Java
23:26
Jakob Jenkov
Рет қаралды 13 М.
КОНЦЕРТЫ:  2 сезон | 1 выпуск | Камызяки
46:36
ТНТ Смотри еще!
Рет қаралды 3,7 МЛН
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
The Java Memory Model - The Basics
23:41
Jakob Jenkov
Рет қаралды 137 М.
Java ExecutorService - Part 1
20:56
Jakob Jenkov
Рет қаралды 58 М.
38. Java VirtualThreads vs Normal Threads || ThreadLocal in Java
22:44
Concept && Coding - by Shrayansh
Рет қаралды 16 М.
Java Volatile
21:26
Jakob Jenkov
Рет қаралды 48 М.
ThreadLocal in Java
10:59
Defog Tech
Рет қаралды 189 М.
Java ConcurrentMap and ConcurrentHashMap
14:42
Jakob Jenkov
Рет қаралды 2,4 М.
Deadlock in Java
17:48
Jakob Jenkov
Рет қаралды 24 М.
False Sharing in Java
17:33
Jakob Jenkov
Рет қаралды 13 М.