Question: 1 . Inventory Management with Synchronized Methods Write a program simulating an inventory management system for an e - commerce platform. Create a class Inventory
Inventory Management with Synchronized Methods
Write a program simulating an inventory management system for an ecommerce
platform.
Create a class Inventory that holds the stock quantity of a product.
Multiple threads represent customers attempting to purchase items from the inventory.
Use synchronized methods to ensure that the stock quantity cannot go below zero.
Implement a purchaseItemint quantity method in the Inventory class that decreases the stock by the requested quantity. If theres not enough stock, display a
message that the order cannot be fulfilled. Use synchronized methods to manage
access to the stock quantity.
Add a restock method that simulates a restocking process by another thread. This
thread should be able to add items back into the stock periodically while other
threads attempt to purchase items.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
