CSC 1600: Operating System Concepts

Fall 2001

Programming Assignment: Synchronized Account Management

Due: 12/6/01

Project Overview:

The project is to mimic transactions between two accounts. The goals of the overall assignment are:
  • Help you learn Java as a Object Oriented programming language,
  • Help you understand how to create and use threads in Java,
  • Help you understand the importance of thread synchronization, and
  • Help you understand how to synchronize Java threads 
 
In the course of this assignment, you will need to understand the mechanisms for thread management and synchronization within Java.
 
I strongly recommend that you think carefully and make sure you have all the classes and their relationships properly designed before attempting to write any code.
 

Project Part A: Unsynchronized transactions between accounts

 
In this assignment, you will improve the programs from the first assignment:
 
  • The balance of an account MUST reside in the account class, and it cannot be a static variable. In other word, the account class cannot be a class that only provides functions to support other functions/classes.
  • You CANNOT use static modifiers over any function or variables in your classes, except the main function.
  • You MUST use a separate user class to handle transactions between two accounts, instead of letting the main function to handle the transactions. Also, when you instantiate the user class, it must create a new thread to handle the transactions.
  • There MUST be at least three instances of the user class created by the program, i.e. three new threads handling transactions independently.
  • You MUST be able to randomly select from which account the money is being deducted.
  • There MUST be at least 1,000,000 transactions made within each thread, so that it is more likely for the race condition to happen.
  • Do NOT print the balances of the accounts after each transaction, as I explained in the class. You can print the result when debugging, but if you want to see the race condition, you must comment those lines out.
 
After the program is run, you will find out that the sum of the accounts is not the same as the original. Do not panic: that is why we are going to provide synchronization in the threads.
 

Project Part B: Synchronized transactions between accounts

Now, you can synchronize the transactions so that the sum of the balances of the final result of the two accounts will be the original number again. Be careful with deadlocks.
So, for this assignment, I expect you to turn in two sets of file(s), one for each part.
 
 
Congratulations, you have just finished the assignment.
 
 
THINK FIRST BEFORE YOU PUT ANYTHING ON PAPER.