Deadlock Prevention in Java

  Рет қаралды 16,030

Jakob Jenkov

Jakob Jenkov

Күн бұрын

Пікірлер: 33
@alexandergulbrandsen646
@alexandergulbrandsen646 2 жыл бұрын
Struggled with this in college, and you just saved my exam! Thank you. No need to have a lecturer when we have you.
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Wonderful :-D Great to hear I have helped you! :-)
@mahesh958
@mahesh958 Жыл бұрын
Followed this tutorial to build my application for the power plant I work at in Chernobyl. Hope nothing goes wrong. Thanks, Jakob.
@JakobJenkov
@JakobJenkov Жыл бұрын
Well, the terms of service for Java actually says they do not recommend Java for use in nuclear reactors ;-)
@matimozg
@matimozg Жыл бұрын
What a nice and smart code, you're really professional coder, it's pleasure and challenge learning from you
@JakobJenkov
@JakobJenkov Жыл бұрын
Thank you - glad you are getting something out of my videos :-)
@มักโชคดี
@มักโชคดี Жыл бұрын
Solution 1 : UML analysis. Solution 2 : a registerar object, registering every lock by thread and delivering authorisation at locktime and/or release orders.
@JakobJenkov
@JakobJenkov Жыл бұрын
There are many smarter algorithms out there than what I present in this video... here I mostly just present the main ideas !
@มักโชคดี
@มักโชคดี Жыл бұрын
@@JakobJenkov Thanks for your Videos they are of great Help 👍
@vinitamaloo107
@vinitamaloo107 Жыл бұрын
Thank you for the great documentation on your website. I love the content.
@JakobJenkov
@JakobJenkov Жыл бұрын
Thank you :-)
@shelendrasharma9680
@shelendrasharma9680 3 жыл бұрын
Hi Jakob. Nice explanation. you are a mastermind in java.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you ! :-)
@-boiadeiro-
@-boiadeiro- 3 жыл бұрын
nice topic just about the time (learning threads and all that stuff from your site) thanks by the way! very handful and clear explanation
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Great to hear ! :-) ... I am updating my Java concurrency tutorials at the moment, by the way. Not huge changes, but some clarifications here and there.
@DeepakLalchandaniProfile
@DeepakLalchandaniProfile 3 жыл бұрын
Hi, is the twitter handle active ???
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Not yet - but they are working on it inside Twitter - it got hacked - they are working on returning it to me!
@DeepakLalchandaniProfile
@DeepakLalchandaniProfile 3 жыл бұрын
@@JakobJenkov yes I know, get it fixed. 😭😭😭😭
@krzmaciek6010
@krzmaciek6010 3 жыл бұрын
5:20 Hmm... I think that amount of time must be random to acutally help. 5:25: "The amount of time is random" :D
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Yes, each thread should wait a slightly different amount of time to avoid a deadlock ! :-)
@amajor5460
@amajor5460 Жыл бұрын
With the deadlock detection example, would you not allow a thread from acquiring a lock if you can predict using the graph that it would result in a deadlock state? Perhaps it can try to acquire the lock again after some time.
@JakobJenkov
@JakobJenkov Жыл бұрын
You could do various variations of intelligent deadlock detection. Like you suggest, instead of simply detecting when a deadlock has happened - it could also predict that a deadlock _would_ happen if a thread acquired a given lock, and then deny that lock to the thread.
@DeepakPatel-xl3tr
@DeepakPatel-xl3tr Жыл бұрын
Great💥
@JakobJenkov
@JakobJenkov Жыл бұрын
Thanks 😊
@senwang8670
@senwang8670 2 жыл бұрын
Thank you for these great videos Jakob. I am new to multithreading, and have a question after viewing your graph at 15:00 min. So why does a thread have to lock another lock first and then release the lock it has already locked? can a thread release its lock first, and then try to lock another lock? if yes, wouldn't this reduce the chances of getting into deadlock?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Hi Sen, I am glad you liked my videos :-) In some cases a thread can unlock the first lock before locking the second. However, in some cases a thread really need to hold 2 locks before it is thread safe to execute the code of some critical section. It all depends on your code and design. My example simply shows how it can happen. It is then up to you to change your design to avoid it happening ;-)
@quantumlexa
@quantumlexa 3 жыл бұрын
I'm sorry, but that's lol. 07:28. Math.random returns you a double within the range [0.0 - 1.0]. by casting it to long you effectively don't sleep at all, cause it will almost always return zero. please see line 26
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Ah - true ! The cast is in the wrong place! Nice catch! It should be: (long) (100.0 * Math.random()) This is one of the mistakes that sometimes sneak into these video examples. Quite often such mistakes would be caught via a unit test in a real project ... there you could have caught that the sleep time is somehow always zero :-)
@ffatheranderson
@ffatheranderson 3 жыл бұрын
I was typing in live chat.... Though you saw it... I did not know what is "premier", I thought you were "Live". 😥
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Ah, sorry, I normally watch my Premiere's live with the audience - but most of the time there are no questions in the chat :-D ... anyways, the chance is higher of me seeing your comments in these comments below here. By the way, since this is a recorded video, you can just go back to the beginning yourself. You can actually also do that with "live streams". If I get into a live stream after it has started, I often go back to the beginning of the live stream and watch from there. Then, sometimes, I set the playback speed to more than 1.0 - so that I will eventually catch up with the live stream :-)
@rydmerlin
@rydmerlin Жыл бұрын
The lock example would be easier to follow if you just relied on the parameter order to the runnable to switch the order.
Java BlockingQueue
17:48
Jakob Jenkov
Рет қаралды 42 М.
Race Conditions in Java Multithreading
22:39
Jakob Jenkov
Рет қаралды 35 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Deadlock in Java
17:48
Jakob Jenkov
Рет қаралды 24 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 902 М.
Thread Signaling in Java
23:26
Jakob Jenkov
Рет қаралды 13 М.
7 Database Paradigms
9:53
Fireship
Рет қаралды 1,6 МЛН
All Rust features explained
21:30
Let's Get Rusty
Рет қаралды 329 М.
False Sharing in Java
17:33
Jakob Jenkov
Рет қаралды 13 М.
TLS Handshake Explained - Computerphile
16:59
Computerphile
Рет қаралды 571 М.
Java ThreadLocal
14:36
Jakob Jenkov
Рет қаралды 38 М.
The Java Memory Model - The Basics
23:41
Jakob Jenkov
Рет қаралды 135 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 843 М.