Reference no: EM131532805
Consider the following scenario. The WERS development team has determined that the current implementation of WERS leads to a race condition when assigning resources to spills. In WERS, spill kits are resources assigned to an emergency spill. A spill kit is considered an expended resource, which means that each emergency spill must be assigned its own spill kit. A spill kit may not be assigned to more than one spill.
However, developers found that when two or more spills are responded to simultaneously, each response process is in a race for a spill kit. One may grab it first, or they may both "take" the identical spill kit resource simultaneously. If you run the scenario for two concurrent spills you will find that, at least sometimes, WERS will assign the same spill kit to both spills.
Because of the race condition leading to the possibility of assigning one spill kit to two or more spills, WERS must be updated to eliminate this race condition.
To eliminate the race condition, you must update WERS so that two processes never get the same spill kit. Each spill must be assigned a different spill kit. You will need to insure "synchronization" at the moment of requesting the spill kit. You will need to find the narrowest piece of code that Java lets you control and to protect (with synchronized) in order to guarantee each spill is assigned its own spill kit.
Be sure you leave as much concurrency as you can while guaranteeing that the result is always correct. Your task requires an understanding of concurrency and the ability to imagine how the processes might interleave but not much code is involved here. You should experiment with multiple runs for each possible location. Try to repeat runs of your updated WERS until you are convinced you have a correct, minimally synchronized solution.
Once you have completed your updates, confirm the system runs as required.
By Day 7, submit the following:
- The source code for any new or updated classes with appropriate comments (Make sure to include the following comment above your updates: "// CHANGED for THREAD SAFETY IMPLEMENTATION".)
- A brief description of how you determined the narrowest piece of code to protect via synchronized, and a justification for your determination
- Screenshots of the updated system running and showing two spills, even in the same room, getting different spill kits