Some guidelines for this week's studio:
In the zip you installed for this studio, you will find a madeoff package, which contains a version of the Account object you saw in CSE131.
As described in class, the code in this package is not thread safe. Most code is, in fact, not thread safe, but in this case the lack of thread safety poses a problem for the bank.
- Follow the steps below to cause the requisite havoc.
- Ask questions and think about what is happening throughout this part of the studio.
- In the end, you will understand why the code as a race condition and what you can do to ensure the correct operation of the classes.
Do not change the Account class until told to do so, but do convince yourselves that it works properly.
transactions[i] = null; /* FIXME */Replace the null with an instance of an anonymous subclass of Thread that overrides its run() method.
Review your notes from today's lecture and see the extra resources (also posted on the the course calendar):
The runTransactions() method executes NUMTRANSACTIONS transactions, each transferring TRANSFERAMOUNT funds from one account to another. The particular accounts are chosen at random. It is possible that the transfer will take place from and into the same account, which is fine.
The sum of all of the Accounts' balances should be
NUMACCOUNTS × INITIALBALANCE
- What result do you see?
- Note that for each Thread you create, the code I supplied calls its run method. What does that method do with respect to threads?
What is the difference between .run() and .start()?
- If you get tired of waiting, you can terminate the program by clicking on the red-square stop button.
- It is important to understand why you see what you see. Look at your notes from class about deadlock.
- Try to construct a scenario by hand for this program that shows the deadlock.
- Turn this scenario in on paper as part of the studio.
OK so where should synchronization be placed, and why?
As a group, you will design and prototype a GUI for the KWIC lab we did last week. On Thursday during lab, you will integrate your ideas to produce a GUI-driven KWIC.
How should you do this? Design is not something we can do by rote or by formula. This kind of activity requires creativity and a willingness to take risks. Put some crazy ideas out there and brainstorm them as a group.
As a point of reference, I wrote a (let's go with: "straightforward") GUI just to give you an idea of what can be done straightforwardly. I know you can do better.
- Click here to have that experience.This only seems to work in CEC on mirage (or on your Mac if you have one). So please remote desktop to mirage if that helps.
- What swing elements do you see?
- Required: Critical analysis is an important skill in this course. As a group, come up with at least 3 points of critique on my design. Be honest and succinct in your critque, with the goal of giving me feedback to improve my design.
Write at least 3 points of criticism on your studio form to receive credit for this studio.
OK your turn to design a GUI for KWIC. Some notes:
We will talk about PropertyChangeSupport later this semester. For now, view it as notification that you must update the view offered by your GUI based on the KWIC object (the model) changing.