Class BankAccountLockOrdering

java.lang.Object
lock.order.studio.BankAccountLockOrdering

public class BankAccountLockOrdering extends Object
Author:
__STUDENT_NAME__, Ben Choi (benjaminchoi@wustl.edu), Dennis Cosgrove (http://www.cse.wustl.edu/~cosgroved/)
  • Constructor Details

    • BankAccountLockOrdering

      public BankAccountLockOrdering()
  • Method Details

    • transferMoney

      public static TransferResult transferMoney​(Account sender, Account recipient, int amount)
      Transfers a given amount of money from the sender to the recipient. This method should be made thread-safe with the use of synchronized and a lock ordering based on account numbers. In other words, compare the account numbers of the sender and recipient and decide which account to synchronize first depending on those account numbers. Make use of the checkBalanceAndTransfer method given to you to quickly check if there is enough money in the sender's account to transfer the given amount to the recipient. The method should return the result of the transfer. Note: the idea for this method was taken from Java Concurrency in Practice (Chapter 10, pg. 209) and was slightly modified to fit our purposes
      Parameters:
      sender - the Account instance of the sender
      recipient - the Account instance of the recipient
      amount - the amount the sender is trying to send to the recipient
      Returns:
      result of the transfer