-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShop.java
More file actions
32 lines (25 loc) · 745 Bytes
/
Shop.java
File metadata and controls
32 lines (25 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.jspiders.multithreading.resource;
public class Shop {
int availableItems;
public Shop (int availableItems) {
super();
this.availableItems=availableItems;
}
public synchronized void reStock(int noOfItems) {
availableItems +=noOfItems;
System.out.println("Successfully store" +noOfItems+ "Items is in stock");
this.notify();
}
public synchronized void Purxhes(int noOfItems) {
if (availableItems<noOfItems) {
System.out.println("Items out of stock please Wait");
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
availableItems=noOfItems;
System.out.println("Purches of" + noOfItems + "Items successfully");
}
}