From the course: Advanced Java: Threads and Concurrency

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Challenge: Inventory manager

Challenge: Inventory manager

(upbeat music) - [Instructor] It is time for a Code Challenge. Here, you get to use what you've learned so far, like issues related to Java thread memory access and the use of synchronized keyword. In this short challenge, I want you to identify the possibility of a Data Race and/or a Race Condition in the given scenario of inventory manager and use synchronization to prevent it. The inventory manager maintains an item count of 200,000. Let's say it issues 100,000 items and receives another 100,000 items. So the final or current item count is expected to be 200,000. You'll be given the required code to work on the challenge. First of all, run the Main class and see what you get as the output. You may want to run several times and observe the output. You should then carefully go through the code and figure out the reason for the output you got. For example, are there any variables or data shared by multiple threads in the given code? See if you can identify any of the issues that you…

Contents