-
Jan Kožusznik authoredVerifiedc97dc349
TestProducerConsumer.java 2.30 KiB
package lab;
public class TestProducerConsumer {
public static void main(String[] args) {
Buffer buffer = new Buffer(4);
Producer p1 = new Producer(buffer, 1);
Producer p2 = new Producer(buffer, 2);
Consumer c1 = new Consumer(buffer, 1);
Consumer c2 = new Consumer(buffer, 2);
p1.start();
p2.start();
c1.start();
c2.start();
}
}
/***************************************************************************************
EXECUTION EXAMPLE
Producer 1 deposited 1 ==> resources: [1]
DEPOSIT 1
Producer 1 deposited 2 ==> resources: [1, 2]
DEPOSIT 2
Consumer 1 withdrew 1 ==> resources: [2]
Producer 2 deposited 1 ==> resources: [2, 1]
DEPOSIT 1
Producer 2 deposited 2 ==> resources: [2, 1, 2]
DEPOSIT 2
Producer 2 deposited 3 ==> resources: [2, 1, 2, 3]
DEPOSIT 3
Resources at maximum! Producer 2 waiting to deposit a new resource.
CONSUME 1
Consumer 2 withdrew 2 ==> resources: [1, 2, 3]
CONSUME 2
Producer 1 deposited 3 ==> resources: [1, 2, 3, 3]
DEPOSIT 3
Resources at maximum! Producer 2 waiting to deposit a new resource.
Resources at maximum! Producer 1 waiting to deposit a new resource.
Consumer 1 withdrew 1 ==> resources: [2, 3, 3]
CONSUME 1
Producer 2 deposited 4 ==> resources: [2, 3, 3, 4]
DEPOSIT 4
Resources at maximum! Producer 1 waiting to deposit a new resource.
Resources at maximum! Producer 2 waiting to deposit a new resource.
Consumer 2 withdrew 2 ==> resources: [3, 3, 4]
CONSUME 2
Producer 1 deposited 4 ==> resources: [3, 3, 4, 4]
DEPOSIT 4
Resources at maximum! Producer 2 waiting to deposit a new resource.
Resources at maximum! Producer 1 waiting to deposit a new resource.
Consumer 1 withdrew 3 ==> resources: [3, 4, 4]
CONSUME 3
Producer 2 deposited 5 ==> resources: [3, 4, 4, 5]
DEPOSIT 5
Resources at maximum! Producer 1 waiting to deposit a new resource.
Consumer 1 withdrew 3 ==> resources: [4, 4, 5]
CONSUME 3
Producer 1 deposited 5 ==> resources: [4, 4, 5, 5]
DEPOSIT 5
Consumer 1 withdrew 4 ==> resources: [4, 5, 5]
CONSUME 4
Consumer 2 withdrew 4 ==> resources: [5, 5]
CONSUME 4
Consumer 2 withdrew 5 ==> resources: [5]
CONSUME 5
Consumer 2 withdrew 5 ==> resources: []
CONSUME 5
***************************************************************************************/