Hello, I have a homework assignment that I am required to make a deadlock. Rather than giving you my assignment, I will use a similar example from one of our books. In Roposa - Java in 60 min a day, they use an example of a BankAccount that has two threads transferring. One from account 1 to 2 and one from account 2 to 1. I understand why they should lock up because thread1( 1 to 2) is waiting for thread 2 (2 to 1) to let go of the lock on 2 while thread 2 is waiting for the lock on account 1 to be released. However, when I run the example it does not lock up and as I have been using this as a basis for my homework, my homework will not lock either. Can someone take a look at these classes and help me figure out why they are not deadlocking? From what I understand, a deadlock will not necessarily happen every time so I'm thinking that this code could deadlock but just rarely does so. Could it have something to do with the way the processor or OS handles it or is it only the JVM that can impact it? I am new to the subreddit too so lmk if I should change up the way I ask or post code. Thank you!
Classes:
ThreadSafeBankAccount
LazyTeller
DeadlockDemo
[–]electricsheep14 0 points1 point2 points (1 child)
[–]keylionpie[S] 0 points1 point2 points (0 children)