Some guidelines for this week's studio:
In 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 by design, in fact, not thread safe. 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 has 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.
Such passing of time would happen in the real world on a busy system. We need it here to create the kind of environment in which real applications run.
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 yellow lightbulb can help you out, but...
- It is important that you understand what you need to do to fix this.
- Take a look at
- Ask others around you or a TA to explain what's wrong.
- Fix this problem by making the appropriate variable final.
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
- It's not really over until the Done message is printed (this may take about 15 seconds).
- 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.
By clicking on these threads and showing the owned and waited-upon locks, see if you can find a cycle among the threads that explains the deadlock.
If appropriate, use the debugger to explain what you see.
Proceed only if you have time and inclination. You're welcome to try the KWIC GUI part out on your own or later in the semester.
As a group, experiment with WindowBuilder to design a GUI for the KWIC lab we started last week.
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, you saw a (let's go with: "straightforward") GUI designed in class to give you an idea of what can be done straightforwardly. I know you can do better.
- Review the videos if you like:
- What swing elements did I use?
- 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 this design.
OK your turn to design a GUI for KWIC. Some notes:
When you done with this studio, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so