Jakob my beloved, I cannot ever thank you enough. The Java community is a better place with teachers like you in it, thank you!!
@JakobJenkov2 ай бұрын
Thank you very much for your kind words !! :-)
@sreekaransrinath43153 жыл бұрын
Drinking game: Every time Jakob says "lock", take a shot
@JakobJenkov3 жыл бұрын
😊
@michaelmedvedskiy74493 жыл бұрын
got alcohol poisoning ty
@LuneAgent3 жыл бұрын
So if a thread locks a ReentrantLock lock, a lock is locked and will not be unlocked until the lock count of the lock is 0. And before that lock unlocks it blocks the other threads until they get their own chance to lock a lock and increase its lock counter, then they get the lock unlocked and the next thread is ready to lock the lock. Wow, it locks really good.
@kristiyangerasimov67082 ай бұрын
this whole java concurrency series is priceless. Thank you for the great pacing, examples and time spent to record it!
@JakobJenkov2 ай бұрын
Thank you! I am happy you find it useful! :-)
@jober7660 Жыл бұрын
I'm insanely grateful for this series, you explain everything in the best way possible!
@JakobJenkov Жыл бұрын
Thank you !! :-) ... and you are welcome :-)
@shubhamagarwal14347 ай бұрын
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.
@JakobJenkov7 ай бұрын
Thanks a lot ! :-)
@raj_kundalia4 ай бұрын
This is the best tutorial ever. Thank you for doing this!
@JakobJenkov3 ай бұрын
Thanks! ... and you are welcome ! :-)
@CAMOBAP7956 ай бұрын
This the level of explanation that looked for! Great videos!
@JakobJenkov6 ай бұрын
Great !! 😊😊
@amiralitavakoli16043 жыл бұрын
Probably the best tutorial about the Lock interface. also, I can feel semantic satiation happening for you because of the word "lock". 😁
@JakobJenkov3 жыл бұрын
Thanks ! ... yes, it was hard to say the word "Lock" all these times! :-D ... I remember making many mistakes during recording :-D
@LuneAgent3 жыл бұрын
@@JakobJenkov probably it's possible to use another verb instead of "lock" to reduce this effect, maybe like: "lock and unlock the lock" -> "close and open the lock" or "occupy and unoccupy the lock" or "turn on and turn off the lock" or "capture and free the lock" I'm not really sure though, cause locking and unlocking sound the most natural for locks :)
@hero_xiper3 жыл бұрын
Hi, Jakob. Your videos are really useful to me and thanks a lot. Please continue!
@JakobJenkov3 жыл бұрын
Thank you very much! Glad my videos help you! I will continue, although I have less time than I did previously to make videos. But I will release some from time to time - like I just did today (about Thread Congestion in Java).
@smitmandavia504411 ай бұрын
Thanks again for the great detailed videos! :D The best video I could find for multithreading and concurrency. One suggestion is to also explain example use case of lockInterruptible.
@kamelwerghi61784 жыл бұрын
keep up the great work, you deserve to have millions of subs and views 💯
@JakobJenkov4 жыл бұрын
Thanks :-D ... I wish ! ;-)
@ffatheranderson4 жыл бұрын
13:25 now I know what "starvation" means in multithreading context.
@rahulgupta373 Жыл бұрын
I watched various videos but this one was the best. Thanx for such great video. And keep spreading knowledge😁....
@JakobJenkov Жыл бұрын
You are welcome - and thank you for your kind words! :-)
@technophylic332111 ай бұрын
Brother your content is really top notch, keep doing the good work. Thanks 👍🏻
@JakobJenkov10 ай бұрын
Thank you ! I really appreciate your feedback! :-)
@ffatheranderson4 жыл бұрын
22:23 good explanation on use case for try lock.
@utkuceylan2309 Жыл бұрын
Thank you Jakob for this awesome video that enlightened the topic for me!
@JakobJenkov Жыл бұрын
You are welcome! :-)
@vdiitd4 жыл бұрын
Hello Jakob, I just found your channel today while searching for Java multi-threading tutorials. Your videos are the best ones that I have come across. I just realized that this video was posted today while I was watching your playlist on multi-threading. Timely post I guess :D. Are you going to post more videos on this topic?
@JakobJenkov4 жыл бұрын
How lucky 😁 Yes, I plan to still add more videos within this topic. There are several basic topics to cover, and I also want to cover various thread architectures.
@ffatheranderson4 жыл бұрын
Confirmed. I like the quality and detailsation of your videos and articles. Only your competitors are (I would say if you let me) Baeldung and Mkyong. 😊 PS: just realized that Baeldung is not a person 🤣...
@JakobJenkov4 жыл бұрын
Baeldung started out as a single person, but then he started hiring writers.
@vdiitd4 жыл бұрын
@@JakobJenkov That's awesome. Looking forward to learn more from you! 😊
@Simon-fe7ti3 жыл бұрын
I can only second that!
@yonatanshkolsky43962 жыл бұрын
Your tutorials are amazing!!
@JakobJenkov2 жыл бұрын
Thanks :-)
@ManishKumar-qx1kh7 ай бұрын
Hi Jakob, great content as usual but i am adding a small suggestion that you should've explained about other implementations of Lock interface and how many locks are there in java etc.
@JakobJenkov6 ай бұрын
You can look that information up in the JavaDoc :-)
@manojkrishna76933 жыл бұрын
Crystal clear explanation!
@JakobJenkov3 жыл бұрын
Thank you ! Great to hear! :-)
@bocumasix10103 жыл бұрын
Hi Jakob. Your blog and videos are always helpful to me, in getting my job and performing well in it. Have you got a patreon or is there a way I can buy you a coffee? Keep up the great work
@JakobJenkov3 жыл бұрын
Thank you! Glad my tutorials are helpful! I did have a Patreon account once, but nobody every signed up (developers like free stuff ;-) ), so I shut it down again.
@mostafahassan6889 Жыл бұрын
"lock the lock" for the amazing explanation :D
@JakobJenkov Жыл бұрын
Yeah... then that topic is locked in 😉
@leetcodeproblems1169 Жыл бұрын
Hi Jakob, Thnx for such a great tutorial. I wonder How do you create the diagrams which you use during the lectures?
@JakobJenkov Жыл бұрын
I use various diagram software :-)
@andrehalmoussa40772 жыл бұрын
excellent explained
@JakobJenkov2 жыл бұрын
Thank you very much 😊
@aymmen65383 жыл бұрын
Hi Jakob, thank you for your good explanation and your efforts. Just to confirm that the two Counter implementations CounterSynchronized and CounterLock are not equivalents? In the first one, the methods inc() and getCount() can be called "simultaneously" by two threads. In the second one, the same Lock Object is used in the two methods, so they can't be called "simultaneously" by two different threads.
@JakobJenkov3 жыл бұрын
No - in CounterSynchronized only 1 thread can call either inc() or getCount() at a time, because both methods are synchronized (on the object instance). That is also the case with CounterLock.
@19891214ful8 ай бұрын
Im dizzy hearing lock 😵💫 Btw great video.
@JakobJenkov8 ай бұрын
Thanks 😅
@Manuel-oe4gv Жыл бұрын
Hi Jokob at minute 10:24 lock is called one time in the calculate method. How is it possible to execute add/subtract if the lock was already called without unlock ?
@JakobJenkov Жыл бұрын
If a Lock is reentrant, a thread can lock the same lock more than once, and yet only one unlock() call is necessart to unlock it.
@redcrafterlppa3033 жыл бұрын
4:30 interesting, i didn't know that finally was stronger than return.
@SEASLU3 жыл бұрын
Thanks for sharing Jakob. Just wonder if you've covered Condition anywhere?
@JakobJenkov3 жыл бұрын
What exactly do you mean by "Condition" ?
@SEASLU3 жыл бұрын
@@JakobJenkov I meant this one docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Condition.html
@BJ-xg7io3 жыл бұрын
Hi Jakob, the tutorials are great, in fact I can say its the best I have found so far on multithreading. One question I have is for the tryLock() example. When thread3 is in queue and waiting for 1000ms, does it need to be next in line to be able to lock the Lock or can it be in any part of the queue and will still be able to lock the Lock if the Lock is unlocked during that 1000ms time?? From what you said in the video, I think the thread has to be next in line to be able to lock the Lock but just want to confirm if I understand it correctly.
@JakobJenkov3 жыл бұрын
When in doubt about a detail like this, it can be a good idea to check the official JavaDoc for the given method. There you can often find such details listed. The tryLock() method without a timeout does *not* respect other threads waiting in line to lock the ReentrantLock. The tryLock(timeout) method - the version with a timeout - *does* respect other threads waiting in line to lock the Lock. See the official JavaDoc here: docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/concurrent/locks/ReentrantLock.html#tryLock(long,java.util.concurrent.TimeUnit)
@BJ-xg7io3 жыл бұрын
@@JakobJenkov Thanks so much!
@tomasma48963 жыл бұрын
Is that lock needed for a getter when inc is already synchronized ?
@JakobJenkov3 жыл бұрын
Since reading a variable doesn't change it - synchronization / locking is not necessary to guarantee correct behaviour. However, to guarantee "visibility" of the variable that is protected by the Lock - you should consider locking and unlocking when accessing it (or make the variable itself volatile).
@COFFEEWITHJAVA3 жыл бұрын
I believe usually we do not apply locks to reading the variables. As per Jacob, I learnt that making writes to variables definately will require locks to perform this kind of operation and also to make it visible what changes you are making, you need to make that variable volatile. Otherwise, there is no guarantee that your changes are shown to other threads also. Hence, usually for a method like setter makes sense to have keyword like synchronized. Correct me if I am wrong, Jacob :) .
@abodalatrash18602 жыл бұрын
Amazing bro
@JakobJenkov2 жыл бұрын
Thanks :-D
@av983 жыл бұрын
Thank you for the video.
@JakobJenkov3 жыл бұрын
You're welcome !!
@leetcodeproblems1169 Жыл бұрын
Hi Jakob, One Question when a thread acquires a lock then why it needs to acquire the lock again which is basically the ReEntrant lock?
@JakobJenkov Жыл бұрын
It does not _have to_ - but in case your code does it - if the lock is reentrant, it will not cause any problems retaking the lock by the thread that already holds it.
@Felitsius2 жыл бұрын
great video!
@JakobJenkov2 жыл бұрын
Thanks 😊
@มักโชคดี Жыл бұрын
Thanks Jacob.
@JakobJenkov Жыл бұрын
You are welcome! :-)
@kaixunzhang47022 жыл бұрын
Hi Jakob, thanks for the wonder explanation!! However, your website is down. Can you please check?
@JakobJenkov2 жыл бұрын
Hi Kaixun, thank you for notifying me! ... the server hosting tutorials.jenkov.com is getting old, and has become a bit unstable unfortunately. This is the 3rd crash within a short time period. I will be moving all the tutorials to jenkov.com soon though (a few are already moved) .
@lawjibran49783 ай бұрын
Checking to see if current thread is queued isn't it unnecessary since the thread will be blocked trying to get the lock. At (26 min)
@nickfast86243 жыл бұрын
Are there any difference if you put lock.lock() right before try-finally block and not within try block? For example The art of multiprocessor programming suggest the approach with acquiring lock before entering try block.
@JakobJenkov3 жыл бұрын
There should not really be any difference there... except if lock.lock() can throw an exception you are interested in catching somehow.
@aymmen65383 жыл бұрын
Another question : are there really a benefit when making the count property volatile ?
@JakobJenkov3 жыл бұрын
In this case - no, there is not. The access pattern (check-then-update) means that simply using a volatile variable is not enough - you need the atomicity of a synchronized block, or a critical section guarded by a Lock. However, once you have a synchronized block or a block guarded by a Lock, you no longer need the variable to be volatile - because the synchronized block / Lock guarded block provides the same visibility guarantees as a volatile variable does.
@khomo122 жыл бұрын
Great!
@JakobJenkov2 жыл бұрын
Thanks :-)
@redcrafterlppa3033 жыл бұрын
3:30 the lock variable needs to be static
@JakobJenkov3 жыл бұрын
No it should not an instance variable because it protects that single object. Otherwise it would lock all objects of that class.
@SebastianBandera4 жыл бұрын
Muy bueno !!.
@JakobJenkov4 жыл бұрын
Gracias 😊
@minasalah82103 жыл бұрын
thank you.
@JakobJenkov3 жыл бұрын
You're welcome !
@tobias72563 жыл бұрын
1:24 lock lock lock lock lock
@JakobJenkov3 жыл бұрын
... followed by unlock unlock unlock unlock ... in that exact sequence ;-)
@김도형-g2i3 жыл бұрын
wow..... just wow....
@JakobJenkov3 жыл бұрын
Thanks ! :-)
@prometheusli1013 жыл бұрын
is java lock equivalent to kotlin await?
@JakobJenkov3 жыл бұрын
I don't know Kotin well enough to be able to say, unfortunately!
@principlesoflife1723 жыл бұрын
Whatever expertise.. still he can learn something from you.. I am not sure how can we repay you..
@JakobJenkov3 жыл бұрын
Thanks - I am glad my videos are of helpful to you :-)
@theyaghu2 жыл бұрын
I understand what you said but still I am in confusion can you explain even better. You teaching is excellent but I am not able to understand (my fault )...!!!!!
@JakobJenkov2 жыл бұрын
What part exactly is it you still need some help with?
@klajdi9656 Жыл бұрын
take a shot every time it says lock
@JakobJenkov Жыл бұрын
It better be a shot of something healthy then ;-)
@TWIND-i5vАй бұрын
“LOCK LOCK ”“LOCK THE LOCK ”“LOCK THE LOCK ”“LOCK THE LOCK ”“LOCK THE LOCK ”“LOCK THE LOCK “HE LOCK ””......