Not a single video on KZitem matches this level of clarity and extensiveness about multithreading. Hats off to you.👌
@JakobJenkov
Жыл бұрын
Thank you 😊
@halavich9672
8 ай бұрын
Totally legit!
@raj_kundalia
6 күн бұрын
This content is gold. After almost 8 years, I keep on knowing things that I did not know before, not just this particular video but the whole series. Thank you, Jacob.
@JakobJenkov
5 күн бұрын
You are most welcome !! 😊😊
@fuadgafarov
3 жыл бұрын
I am never seen tutorials with such clear explanation. Thank you Jakob.
@JakobJenkov
3 жыл бұрын
Thanks! I am glad you found my tutorials helpful :-)
@RaghuVN
3 жыл бұрын
A few years back, one of my friends suggested your tutorial for angularjs. It was easy to understand tutorial, compared to a lot of tutorials I went through. I searched for you and found this playlist of java multithreading, which is equally good. Great and very useful content. Thanks for sharing it. You deserve a lot more views and subscribers.
@JakobJenkov
3 жыл бұрын
You are welcome! :-)
@shubhamagarwal1434
3 ай бұрын
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
3 ай бұрын
Thanks :-)
@shilankalhor2072
3 жыл бұрын
I think after all these years working with java, this is the first time I have understood the synchronization. Many thanks. I wish you also had videos about nio and io. It’s just easier when you explain them.
@JakobJenkov
3 жыл бұрын
Thank you 😊
@OKelvinClark
3 жыл бұрын
I have to watch these videos at least twice because the content is too complex for my head. Thank you very much for making this matter clearer and easier to understand. This motivates me not to give up on this subject and keep learning.
@JakobJenkov
3 жыл бұрын
I have books that I have read up to 5 times before I finally understood and remembered it all... just gotta keep at it. If I don't understand one book, or only part of it, I will try another one, and another one etc. Or another article, tutorial or video. Piece by piece I understand more and more of the topic, and one day I understand most of it.
@marcusrigonati7784
3 жыл бұрын
I thought "Let me see some explanation so I can understand a little bit more about Sync" and then this video explains perfectly everything I need to know, thank you man!
@JakobJenkov
3 жыл бұрын
Great to hear ! :-) ... this video became longer than I had originally planned, but then I thought - why not just go deep into the details now that I am at it?
@stylishsannigrahi
3 жыл бұрын
The way you explain and takes deep dive, makes you to stand out from others ..amazing stuff.. much gratitude
@JakobJenkov
3 жыл бұрын
You are welcome! :-) ... it is actually possible to dive even deeper into all these topics - about what happens inside the Java VM etc. - but since the VMs change over time, going so deep might not be up-to-date in a few years.
@viranchpatel5071
2 ай бұрын
This Multithreading playlist is something invaluable! Hats off to you Jakob :)
@JakobJenkov
2 ай бұрын
Thank you very much! I am happy it's useful to you ! :-)
@shirshendudebroy2097
4 жыл бұрын
Awesome Tutorials on Concurrency... I was going through the Udemy Java course but now I am only watching your videos... Love from India...
@JakobJenkov
4 жыл бұрын
Haha - cool - thanks 😁
@calumjb
3 жыл бұрын
These are the best tutorials I have ever seen on KZitem, ever, for anything. I rarely comment but I have to thank you. Keep up the good work and I'm positive you'll go far.
@JakobJenkov
3 жыл бұрын
Wow - thank you very much for your kind words!! :-)
@zhenlinjin3142
3 жыл бұрын
Thank you, Jakob! You're awesome. I was having difficulty understanding the those mutlithreading concepts while preparing for big-n interviews. Your videos and blogs help tremdously!
@JakobJenkov
3 жыл бұрын
I am happy to hear my tutorials have helped you! 😊
@LOKeshrangineni
4 жыл бұрын
Thanks Jakob. I used to be a follower of your site a long time ago. Luckily I have found your video on youtube when I wanted to revisit my skills on threads. Very nice explanation with different examples. Thanks a lot for your efforts in providing quality content.
@JakobJenkov
4 жыл бұрын
You are welcome! I've got more videos on Java concurrency coming :-)
@LOKeshrangineni
4 жыл бұрын
@@JakobJenkov I am waiting here for your future videos. Meanwhile going through your blog in preparing for an interview.
@anothermouth7077
12 күн бұрын
Dude, i refer to your java portal quite often! Didnt know you have youtube channel. Instant subscribe
@JakobJenkov
10 күн бұрын
Thank you! :-) ... I don't have nearly as many videos as I have textual tutorials, and it will probably stay that way, but I keep making videos from time to time :-)
@anothermouth7077
10 күн бұрын
@@JakobJenkov understandable. Unless there's some cool trick or technique or gotchas to show , your textual blogs works just fine :)
@simongupta8724
2 жыл бұрын
Wow, thanks so much for this video. I just started the topic multi-threading and when I got the first infos about it, so many questions were left open. Your tutorial made many things a lot clearer and I certainly will go on watching more of your videos for details on other aspects like the Happens Before Guarantee. It's so great, that there are videos/video collections like this on youtube which cover the topics with some deepness.
@JakobJenkov
2 жыл бұрын
Thank you very much for your kind words! I am happy that my videos have helped you ! :-)
@Jaraqqeh
3 жыл бұрын
I like your tutorials because you cut to the chase and describe everything clearly and with minimum bs.
@JakobJenkov
2 жыл бұрын
That's what I try to do - so I am glad that is also your perception!
@druzzyaka
2 жыл бұрын
the best explanation of java multithreading i've ever seen
@JakobJenkov
2 жыл бұрын
Thank you :-)
@abdurrehman7234
3 жыл бұрын
If i need to learn something in Java, First thing that comes to mind is your blogs and YT channel, Amazing content
@JakobJenkov
3 жыл бұрын
Thank you very much ! I am happy to hear that !! :-)
@omnipoten8
4 жыл бұрын
Excellent explanation. Would like this to be the video that should be used in classrooms to explain Java synchronization to students . Thanks for the video !
@JakobJenkov
4 жыл бұрын
Thank you very much :-) ... well, aren't many students anyways supplementing their classroom material with KZitem and online tutorials?
@omnipoten8
4 жыл бұрын
@@JakobJenkov I am sure they are :-) . I just wanted to make this video official to be presented in classrooms ;)
@e2bvideos
2 жыл бұрын
Great videos Jenkov, very helpful. One more thing that could be done is that, you can upload the diagrams and code to a git repo. That would be really helpful
@Jay-nc1wr
10 ай бұрын
You have an amazing skill to teach and describe complex topics in a easy to understand manner, thank you. I agree, you should make a course and put your material on there.
@JakobJenkov
9 ай бұрын
Thank you very much !! I might make a course one day ! :-)
@bharatprakashparakh9601
6 ай бұрын
Best explanation on this planet ! Thank you for creating such a wonderful content
@JakobJenkov
5 ай бұрын
You are welcome! :-)
@waresnite
3 жыл бұрын
One of the Best java concurrency tutorials that i've found. Keep It up! pls!
@JakobJenkov
3 жыл бұрын
Thanks! I will try! :-)
@iurysza
4 жыл бұрын
Excellent material! This what people actually need when learning this concepts. While I'm very happy this content is free, I hope you open some kind of funding for your videos so you can keep doing them. Please keep doing what you're doing =)
@JakobJenkov
4 жыл бұрын
Thank you very much !!! I Once opened a patreon account, but I did not get any backers, so I closed it again 😁 ... so now I just make standard videos with a bit of ads in... not a big deal, but it pays a coffee from time to time 😁
@abhisheksengupta4159
3 жыл бұрын
@@JakobJenkov This is really a noble work, Thanks for sharing your knowledge :D
@EpicKillstreak
3 жыл бұрын
@@JakobJenkov Agreed that this is a great content, explained very well, thank you. One thing you could always do is to put a link to PayPal in the description, so those who want can actually thank you in that way. : 3
@ChamaChama205
2 жыл бұрын
Thank you for being thorough and for doing a great job of explaining everything, this was very informative and helpful!
@JakobJenkov
2 жыл бұрын
You are very welcome :-)
@rishabhdhiman2865
Жыл бұрын
You are like Andrew Ng of multithreading, breaking down things to their fundamentals
@JakobJenkov
Жыл бұрын
Thank you 😊 I think Andrew Ng knows more about AI than I knoe about concurrency, though 😊
@VLADICA94KG
3 жыл бұрын
Thank you so much for such a concise and clear presentation! Please keep uploading such a great content!
@JakobJenkov
3 жыл бұрын
You are welcome! Glad it helped you! ... I will continue making more videos when I have time :-)
@mdziaularfeen8436
3 жыл бұрын
@@JakobJenkov Please do, specially contents which are usually misunderstood or not explained by many will help a lot. Grateful for your work. 😊
@crazy-boy6143
2 жыл бұрын
AWESOME. A pretty clear explanation. Could fix an annoying bug in my code thanks to you. I appreciate it
@JakobJenkov
2 жыл бұрын
Great ! :-)
@yonatanshkolsky4396
2 жыл бұрын
Wow. you explained this better then my professor!!!
@JakobJenkov
2 жыл бұрын
:-D ... I am happy it helped you. To be fair to professors, with videos you can go back and rewatch until you understand it. That's not possible with a live professor lecture - so the experiences will probably be different :-) ... but in a live lecture you can ask questions - which you cannot do to a pre-recorded video...
@suttonc1338
2 жыл бұрын
Hello, Jakob. I found your website by accident and was amazed by the quality of your content. Excellent job! If you make any Udemy course, please let me know. I would love to buy your class. Keep up the good work.
@JakobJenkov
2 жыл бұрын
Hi Sutton, thank you very much for your kind feedback! :-) I don't have any Udemy courses available - but I am thinking about writing a book soon. It will be about some advanced Java topics though... maybe not that interesting for everyone :-)
@cocko1425
Жыл бұрын
Amazing, thank you so much!
@JakobJenkov
Жыл бұрын
You are welcome 😊
@nadavkopit
15 күн бұрын
Thanks a lot! Top notch explanation and examples.
@JakobJenkov
13 күн бұрын
Thank you! :-)
@hotbarango
3 жыл бұрын
Best video on the internet on the topic! 👍
@JakobJenkov
3 жыл бұрын
Wow, thanks! :-)
@isurucumaranathunga
3 жыл бұрын
Such a outstanding explanation. Thank you so much
@JakobJenkov
3 жыл бұрын
You are welcome, Isuru :-)
@taoma9293
7 ай бұрын
Great lesson! 😊
@JakobJenkov
7 ай бұрын
Thank you !! 😊
@sagnik4u007
4 жыл бұрын
Awesome explanation
@JakobJenkov
4 жыл бұрын
Thank you! :-)
@kundanKumar-cc7qt
Жыл бұрын
Thanks, Jakob. The content is very useful.
@JakobJenkov
Жыл бұрын
Great! :-)
@athisii_ekhe6167
2 жыл бұрын
Very helpful. Thank you.
@JakobJenkov
2 жыл бұрын
You are welcome! :-)
@magzhanabdibayev3818
3 жыл бұрын
Thank you, Jakob. Really well explained
@JakobJenkov
3 жыл бұрын
You are welcome! Glad it was helpful!
@vasilismora5147
Жыл бұрын
Hello Jakob! The tutorials are very good, have helped me very much! A note for 21:40. I think Java saves strings to String Constant Pool. So if a String is already in the pool, java returns that and it does not create a new string object.
@JakobJenkov
Жыл бұрын
Constant strings may be stored in the String constant pool. But as far as I know, a new String("value") would not. But to be sure - it's better to just stay away from using String objects as monitor objects.
@islombekmamatqulov7821
2 жыл бұрын
Thank you very much Jakob
@JakobJenkov
2 жыл бұрын
You are very welcome! :-)
@hussamkd6327
2 жыл бұрын
Perfect explanation. Thank you!
@JakobJenkov
2 жыл бұрын
You are welcome :-)
@gaminggot8472
3 жыл бұрын
Great movie, thank you Jakob!
@JakobJenkov
3 жыл бұрын
You are welcome - and thank you too! :-)
@sangsokea
2 жыл бұрын
thanks so much sir, that help me save the time a lot
@JakobJenkov
2 жыл бұрын
That's great! :-)
@sajjadvalaei2535
2 жыл бұрын
I appreciate your content thank you.
@JakobJenkov
2 жыл бұрын
You are welcome! :-)
@devtoro5601
2 жыл бұрын
i'm so Lucky to know this lecture. thanks!
@JakobJenkov
2 жыл бұрын
You are welcome! Glad you liked it! :-)
@minepolz320
4 жыл бұрын
Thanks for the video very good explanation
@JakobJenkov
4 жыл бұрын
You are welcome :-)
@user-ri4tw2dw9q
4 жыл бұрын
Finding this treasure through your blog JenKov! From today, i Fucking Love Danish! haha
@JakobJenkov
4 жыл бұрын
Thanks :-D ... happy to help people all around the world with the stuff that was hard for me to learn!
@satishmhetre5542
Жыл бұрын
14:32 This is just a reminder for me when I come next time to watch
@jeffenriquez9929
2 жыл бұрын
Thank you for making this video!
@JakobJenkov
2 жыл бұрын
You are welcome :-)
@vipul1246
3 жыл бұрын
Can't believe this stuff is free. I don't think any paid course about multithreading can match this level.
@JakobJenkov
3 жыл бұрын
Thanks :-D ... well, the more we all know, the better software we can write, and the better it is for everyone ;-)
@vipul1246
3 жыл бұрын
@@JakobJenkov keep making these free content for all. So , those who can't afford can still also gain knowledge.
@dominikpiegdon248
3 жыл бұрын
Really, really good tutorial, thanks Jakob for it! ;)
@JakobJenkov
3 жыл бұрын
You are welcome! :-)
@thushalyaweerasuriya4641
3 жыл бұрын
it is really good..thank you ..love from srilanka
@JakobJenkov
3 жыл бұрын
You are most welcome :-)
@airchairairflare
Жыл бұрын
Great tutorials
@JakobJenkov
Жыл бұрын
Thank you very much :-)
@meetanupam
2 жыл бұрын
Excellent!
@JakobJenkov
2 жыл бұрын
Thank you! :-)
@cypherllc7297
7 ай бұрын
Hi Jakob, Does using a synchronized keyword on a function mutex lock all the objects that are either directly in the scope of that function or called inside that function? Cause the Autowired beans I have used are getting locked and hence blocking parallel runs.
@JakobJenkov
6 ай бұрын
No - it only "locks" the object which the synchronized block is synchronized on - which is either "this" or an explicit object passed as argument to the synchronized block construct. Objects that are referenced from inside a synchronized block can be referenced from outside that synchronized block too - without being blocked. Of course it is up to you to determine if you want that or not (often you don't want that - because why would you reference the object from inside a synchronized block if you do not want access to it to be guarded ?)
@smitalpatel
3 жыл бұрын
In the example around 7:34 , viewers can try removing the synchronized keyword from method signature. You will see the diff in output. I got below Set Object : 0 Get Object : null Get Object : 0 This means without synchronization, 2 threads could enter set & get method at same time. And even though the set method was called first it couldn't complete assigning value 0 to obj variable, & so Thread 2 calling Get method printed null. And just after printing null, the Get method printed 0 as the set method must have completed assigning the value 0 to obj. This can be called Race Condition. This will not happen in case the method is synchronized, the Get method will always print what set method has printed last, because only one thread can enter either method & once entered it will surely complete its task first. FYI: I printed the values inside the set & get method in the first lines of respective methods. So value assignment is after the print.
@JakobJenkov
3 жыл бұрын
Good experimentation work ! It's fun to see how practice corresponds to the theory, right? 😊
@smitalpatel
3 жыл бұрын
@@JakobJenkov exactly Jakob. BTW thanks for this video. Forgot to thank you as i was too focused on example. I am good in Java. But never was i this clear on the topic. This video helped me a lot. Also i wrote same code to understand it more clearly, which also allowed me to experiment. Thanks a lot again.
@chupapimunanyo2596
Жыл бұрын
Incredible explanations… How did you learn all of this? Or have you been told by somebody else
@JakobJenkov
Жыл бұрын
I had to read a lot of books and articles, and watch videos and presentations. It's hard to find good information about Java Concurrency.
@-boiadeiro-
3 жыл бұрын
very nice video & examples
@JakobJenkov
3 жыл бұрын
Thank you! 😃
@putyovka
Жыл бұрын
35:42 @JakobJenkov It took me a few minutes to understand how could both threads reach 2 million after adding the synchronized keyword to both getCound() and incCount() methods, as it did not make sense first, as I thought that the thread finishing its execution first would reach at most (2M - 1). But I think I get it now: the code in the runnable implementation/lambda is not synchronized, only the methods that they are calling. So it could happen that the two getCount() calls in the Sysout statements will be executed just after both for-loops are finished. Maybe it would worth a little explanation, as a minute before you seem to be hinting to something similar to my initial thought -- although that first statement is not exactly clear. Or am I missing something? :) Love your videos btw, cheers!
@JakobJenkov
Жыл бұрын
I agree, normally one thread reaches 2M-1 or lower when finishing, and the other thread reaches 2M. But - in rare situations they might both increment their final time almost simultaneously, and then both will obtain 2M when getting the count.
@SoeaOu
3 жыл бұрын
great stuff, explained well
@JakobJenkov
3 жыл бұрын
Thanks! :-)
@mohamedkhaled6370
2 жыл бұрын
Hello Jakob, I really appreciate your content But I think there is a mistake here 24:44 You've said that we cannot use "this" as a monitor inside a lambda as Lambdas don't belong to any object, but the error is actually because of that you cannot access "this" from the static main. I have passed "this" as monitor to lambda inside an instance method and it worked, Hope you clarify.
@JakobJenkov
2 жыл бұрын
I would not be able to comment on that without seeing the code. Passing "this" from outside of a lambda into a lambda - is not the same as referencing "this" directly inside the lambda. Nor is refereencing "this" via the class where the lambda is created - as this references the "this" belonging to the object outside the lambda - not the lambda itself.
@mohamedkhaled6370
2 жыл бұрын
@@JakobJenkov Hi again :) Here is the Code public class LambdasAndMonitors { static Object object; public static void consumeObject(Consumer consumer){ // not synchronized consumer.accept(object); } } // main LambdasAndMonitors.consumeObject((obj) -> { synchronized (this){ // there is a Compile error here regarding "this" System.out.println(obj.toString()); } }); The error says: "this" cannot be referenced from a static Context // which is the main method and the suggestion is: Make 'main' not static
@khomo12
2 жыл бұрын
Great!
@JakobJenkov
2 жыл бұрын
Thanks 😊
@ivanocj
4 жыл бұрын
I don't know why, but in your videos KZitem keep using 360p as default to me. I need to manually change to 1080p. It is not my connection (240Mbps) because I watch many other ones with very good resolution. That happens only with videos in your channel.
@JakobJenkov
4 жыл бұрын
Strange... the videos are uploaded in 4K !
@LOKeshrangineni
4 жыл бұрын
@ivan - mine is playing at 720 p without any manual intervention. so definitely something with your internet connection.
@lilianetop8307
3 жыл бұрын
@35:38 Why is the count of Thread1 != 2M? The methods are synchronised so I expected that both Threads would end op with 2M.
@JakobJenkov
3 жыл бұрын
One of the threads will finish its 1 million iterations before the other. That is inevitable. The thread that finishes first will not see a total count of 2 million. The highest possible count it can see is 1.999.999 - since the other thread is not yet finished with its 1.000.000 iterations.
@Premkumar-eq1zv
Жыл бұрын
You are legend 🙂
@JakobJenkov
Жыл бұрын
Thank you 😄
@garimadhanania1853
4 ай бұрын
Awesome!
@JakobJenkov
4 ай бұрын
Thank you ! :-)
@mrrishiraj88
11 ай бұрын
thank you.
@JakobJenkov
10 ай бұрын
You are welcome! :-)
@asankasiriwardena3383
2 жыл бұрын
Thanks Jakob! I have a question regarding the final section (synchronized blocks in multiple JVMs) though. As I know same object cannot be shared across multiple JVMs. Therefore is it fair to talk about thread blocking across multiple JVMs on same synchronized block? Or do you intend an edge scenario like a common JNDI store across multiple JVMs to share an instance?
@JakobJenkov
2 жыл бұрын
You cannot block threads across multiple JVMs with a synchronized block. You will need to implement a different mechanism to block threads across multiple JVMs.
@asankasiriwardena3383
2 жыл бұрын
@@JakobJenkov Assume We have somehow managed to share an object across JVM, only then we can apply any other different mechanism to block threads across JVMs?
@writetoyourdestiny
Жыл бұрын
Thanks for the great lessons but I have one question: Let's say in Main RAM the counter is 0. Then in Thread #1 we increment counter right before synchronized block therefore in our local cache or CPU register this value is 1. And when we go into synchronized block it leads us to read value again from Main RAM where the value is still 0. Does it mean that we lost incrementation eventually? The code like this: public void someMethod() { counter++; // 1 synchronized(this) { counter++; // 1 or 2? Will we lost incrementation here since synchronized block guarantee that we update value from Main RAM where the value is 0? } }
@JakobJenkov
Жыл бұрын
I am not actually sure what would happen in that situation. Obviously you *should* increment the counter inside synchronized block - not outside - but if you did what you show in the code example there, I am not sure what the final result would end up being.
@KuldeepYadav-jw7jn
3 жыл бұрын
What will happen if we provide new String("some") reference as a monitor object? Will it work?
@JakobJenkov
3 жыл бұрын
In theory, that should work. However, the convention is to either synchronized on just an Object instance, or synchronize on the shared object being accessed. The problem with using String instances is mostly if some day someone uses a constant String as monitor object. Especially if the same constant string is used in different places as monitor object - to guard different unrelated critical sections.
@KuldeepYadav-jw7jn
3 жыл бұрын
Yeah, got it, thank you 👍
@DeepakLalchandaniProfile
4 жыл бұрын
Hi Jakob, Can you upload the examples to your website as a zip file for download ?? Please reply ( I cannot copy and try it on ide ) ☹☹
@JakobJenkov
4 жыл бұрын
I am getting more requests for the code behind videos. Always first check out the link to the textual tutorial in the description below the video for code samples. Maybe in the future I might add a GitHub repo for code examples.
@DeepakLalchandaniProfile
4 жыл бұрын
Hi Jakob, 1. I just checked for the textual tutorial link for Java synchronized. It is not updated in the description of this video 2. Looking forward for your github code of Concurrency
@tula1308
2 жыл бұрын
I disagree at 4:00 if I call setObj with thread1 I can also use thread 2 to call getObj at the time thread 1 is running
@JakobJenkov
2 жыл бұрын
Not at the exact same time. Since all the methods are synchronized at the object itself (this), then only 1 thread can enter any of these synchronized block at a time. All other thread must wait until no other thread is executing inside any of these synchronized blocks - before they can enter one of these blocks.
@monterYO
Жыл бұрын
thx
@JakobJenkov
Жыл бұрын
Welcome :-)
@sahilkalamkar5332
Жыл бұрын
About one of the problems you mentioned, when the write method to the monitor object has to be written by a single thread at a time, but multiple threads should be able to read, Can't we solve that using a single synchronized method for writes , but for read we keep it non synchronized?
@JakobJenkov
Жыл бұрын
No. If you have the read method non-synchronized you lose the thread visibility guarantee of the synchronized block. In other words, you have no guarantee about when a reading thread will refresh it's currently cached value (of a variable) from main memory (which in practice is somewhere in the cache memory).
@sahilkalamkar5332
Жыл бұрын
@@JakobJenkov Thanks for the confirmation. Also when using synchronized blocks for counters, it's not guaranteed that the values are flushed and refreshed from RAM right? So should we use volatile keyword as well?
@OmprakashYadavIIT
3 жыл бұрын
simple awesome..
@JakobJenkov
3 жыл бұрын
Great to hear you liked it! :-)
@journeytothedream6127
3 жыл бұрын
what about semphore! cant we use that instead of synchronised ?
@JakobJenkov
3 жыл бұрын
Yes, a Semaphore can also be used, and also a Lock, or ReadWriteLock, as well as other constructs. The Synchronized block is just the most basic of them.
@journeytothedream6127
3 жыл бұрын
@@JakobJenkov ❤️
@leniedor733
3 жыл бұрын
So actually there's difference using ::: synchronized (this) {} and synchronized (ClassName.class) {} ??
@JakobJenkov
3 жыл бұрын
Yes ! A big difference ! ... synchronized(this) {} synchronizes on the object, meaning only one thread at a time can enter a block synchronized on the same object - but if the threads access different objects of the same class, there is no problem. When you synchronize on the class object (synchronized(TheClass.class) {} ) - then it doesn't matter if the method belongs to an object, or if it is static - then only 1 thread can access that method at a time - because there is only one class object for a given class in the Java VM.
@leniedor733
3 жыл бұрын
@@JakobJenkov Simple explanation and clear. Thanks Jakov!
@KlanBr1
Жыл бұрын
how do you do the desing of this concurrency software? can do this with the UML? how do you do the abstraction process?and is it include on any of your videos? on the object orientation paradigm, and functional paradigm can be a plus
@JakobJenkov
Жыл бұрын
Pen and paper :-) ... I don't use any special software or techniques.
@KlanBr1
Жыл бұрын
@@JakobJenkov and what about the relation between entities how do you identify? i mean in poo you have 3 kind of relation between entities, it's the same when you have concurrency?
@lucasrodriguesdelima8697
2 жыл бұрын
I have been experimenting Java thread visibility problem with the popular example of sending a stop signal to the thread by means of a shared boolean and non-volatile variable and the target thread does not seem to get it) as below: public class ThreadVisibilityTest { //Shared variable to send a signal to the thread static boolean stopped = false; public static void main(String[] args) throws Exception { Thread targetThread = new Thread(new Runnable() { public void run() { while(!stopped) {} System.out.println("Target thread gets signal and stops..."); } }); targetThread.start(); TimeUnit.SECONDS.sleep(5); stopped=true; System.out.println("Main thread has sent stop signal to the thread..."); } } Main thread sends stop signal to the target thread after 5 seconds by means of setting stopped to true and the target thread can not get it and so does not stop. Defining stopped variable as volatile obviously solves the problem. Bu then I realized that if I make stopped variable non volatile but instead access it in a synchronized context in the target thread, target thread gets the final value and stops. So thread visibility problem seems to be solved just like using volatile. Thread targetThread = new Thread(new Runnable() { public void run() { while(true) { synchronized(this) { if(stopped) break; } } System.out.println("Target thread gets signal and stops..."); } }); And also the object monitor to be used for synchronization seems to have no effect as follows: synchronized(Thread.class) { if(stopped) break; }
@JakobJenkov
2 жыл бұрын
You could also create an explicit class for your Runnable, and have a "stop" field in that. That way you would be able to stop different threads individually, rather than stopping all the threads looking at your shared "stopped" variable.
@lucasrodriguesdelima8697
2 жыл бұрын
@@JakobJenkov In the above example I am reading it in synchronized context but not writing in the synchronized context. Even so, thread visibility problem seems to be solved just like using volatile. Is this something that happens by chance or do I miss something? I read your tutorial on synchronization and in it you say that there is no guarantee when the Thread will flush CPU registers to cache memory. In this example, did simply reading a synconized block (which could be empty) force the Thread that wrote the value to the variable - outside a synconized block, to flush the CPU registers to cached memory? That would be a different conclusion than many books and tutorials claim. Thanks for sharing it !! jenkov.com/tutorials/java-concurrency/synchronized.html
@user-lw5ep2xn3u
2 жыл бұрын
31:52 after removing synchronized block, the result remain the same(I printed the count variable in the inc method). I tested many times.
@JakobJenkov
2 жыл бұрын
I don't get the same results with and without synchronized blocks.
@user-lw5ep2xn3u
2 жыл бұрын
@@JakobJenkov thanks for your reply, i tested many many many times,then i got the different result.
@9229rohit
2 жыл бұрын
@Jakob , which books do you refer to ?
@JakobJenkov
2 жыл бұрын
Where?
@9229rohit
2 жыл бұрын
@@JakobJenkov I really appreciate your deep knowledge and this helped me brush up my 10 years old concepts . That time I used to study from Cathy Sierra for Java 6 . would love to know which books do you refer now and if you can suggest some 😊
@damukukandu8842
2 жыл бұрын
is there a website where you can practice Multithreading?
@JakobJenkov
2 жыл бұрын
I don't know - but I would recommend you to install whatever language compiler you are trying to learn + and IDE, and get it to work on your own computer. You will learn more from that - than from practicing inside a website.
@smejia6362
Жыл бұрын
very well explained but too slow. I'm sure that you can save 10 minutes or more
@JakobJenkov
Жыл бұрын
You can just increase video playback speed :-) Not all people are native English speakers, or understand things in the same speed, so it is hard to find a "perfect" explanation speed. Therefore, I tend to slow a bit down - because it's possible for faster learners to speed up playback :-)
@smejia6362
Жыл бұрын
@@JakobJenkov That advice is really working!! thanks!!
@prateekashtikar8631
3 жыл бұрын
Could you please share code?
@JakobJenkov
3 жыл бұрын
All (or most, at least) of my Java code examples will be available in this GitHub repo (link below). There are more examples in the src/main/java directory than what are currently listed in the README.md file, so browse a bit around to see what's there! github.com/jjenkov/java-examples
@prakritidevverma4315
3 жыл бұрын
My head hurts now U guess too much synchronized with the word "synchronized"
@JakobJenkov
3 жыл бұрын
Hahaha :-D ... yes, it can be necessary to take a break once in a while to let new stuff sink in! I need that very often when I study new stuff myself :-) ... sometimes it almost feels as if I can feel the neurons making new connections inside my brain - that's how much stress it can put on my brain :-D
@prakritidevverma4315
3 жыл бұрын
@@JakobJenkov Its good to know that I am not alone. 😅😢
@prakritidevverma4315
3 жыл бұрын
@@JakobJenkov Do you have anything on spring boot thought ? I'm preparing you my interviews I don't see much of content worthy to watch for interviews. If you can recommend some material that would be great.
@trungpham7588
4 жыл бұрын
...
@user-fp6lw9kc2y
Жыл бұрын
is the reording of instructions take place inside a synchronized block? @JakobJenkov
@JakobJenkov
10 ай бұрын
That is possible, but instructions will not be reordered in any way that will alter the synchronization semantics of the whole synchronized block.
@tarunsingh7608
28 күн бұрын
The MOST Detailed Videos on Multi-threading & Concurrency in JAVA by PROFESSOR Synchronized, a.k.a, @JakobJenkov. These videos SYNC ur Brains on the Most recent concepts of Java threads as of Java 19 😃😃
@JakobJenkov
28 күн бұрын
Thank you very much for your kind and enthusiastic words 😊😊
Пікірлер: 201