/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkgMain;
import java.util.ArrayList;
import java.util.concurrent.CyclicBarrier;
import pkgData.Counter;
import pkgSubjects.Worker;
import static pkgSubjects.Worker.NUMBER_OF_WORKERS_FOR_BIGBOX;
/**
*
* @author schueler
*/
public class Main {
/**
* simulation of potato - pickers who
* empties their baskets in big box
* and next 3 workers load big box on the truck
*
* @param args
*/
private static int NUMBER_OF_WORKERS = 5;
private static int DURATION_OF_SHIFT = 15000; //msec
private static Counter boxCounter;
private static ArrayList collWorkers = new ArrayList();
private static CyclicBarrier cl;
public static void main(String[] args) {
try {
startWorkers();
awaitEndOfShift();
stopWorkers();
printStatistics();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void startWorkers() {
boxCounter = new Counter(0);
long shiftEndTime = System.currentTimeMillis() + DURATION_OF_SHIFT;
cl = new CyclicBarrier(NUMBER_OF_WORKERS_FOR_BIGBOX);
for (int i = 1; i
Подробнее здесь: [url]https://stackoverflow.com/questions/79895960/threads-example-potatopicker-not-working-properly-with-multithreading[/url]