public Factory(int workingDaysLimit) {
this.storage = new LinkedList<>();
this.workingDaysLimit = workingDaysLimit;
this.currentWorkingDay = 0;
}
public Factory(int workingDaysLimit) {
this.storage = new LinkedList<>();
this.workingDaysLimit = workingDaysLimit;
this.currentWorkingDay = 0;
}
public FactionThread(Factory factory) {
this.factory = factory;
this.warehouse = new LinkedList<>();
}
public synchronized void produce() throws InterruptedException {
Random random = new Random();
while (days < 100) {
while (storage.isEmpty()) {
for (int i = 0; i < random.nextInt(10); i++) {
int randomOfDetails = random.nextInt(4);
switch (randomOfDetails) {
case 0:
storage.add(Details.HEAD);
break;
case 1:
storage.add(Details.TORSO);
break;
case 2:
storage.add(Details.HAND);
break;
case 3:
storage.add(Details.FEET);
break;
}
}
days++;
notifyAll();
}
wait();
}
notifyAll();
}
public class Wednesday extends Thread {
private Storage storage;
public Wednesday(Storage storage) {
this.storage = storage;
}
@Override
public void run() {
try {
System.out.println(storage.getDetails());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}