Laboratorul 4
Laboratorul 4
Laboratorul 4
Varianta 2
package com.company;
import java.util.ArrayList;
import java.lang.Math;
producer.setName("Producatorul 1");
producer1.setName("Producatorul 2");
producer2.setName("Producatorul 3");
consumer.setName("Consumatorul 1");
consumer1.setName("Consumatorul 2");
consumer2.setName("Consumatorul 3");
consumer3.setName("Consumatorul 4");
new Thread(producer).start();
new Thread(producer1).start();
new Thread(producer2).start();
new Thread(consumer).start();
new Thread(consumer1).start();
This study source was downloaded by 100000798432454 from CourseHero.com on 02-28-2022 04:23:23 GMT -06:00
https://www.coursehero.com/file/75224912/Laboratorul-4docx/
new Thread(consumer2).start();
new Thread(consumer3).start();
class Store{
while (depozit.size()<1) {
try {
wait();
catch (InterruptedException e) {
depozit.remove(depozit.size()-1);
if(depozit.size()!=0){
System.out.println(" ");}
else{
notifyAll();
This study source was downloaded by 100000798432454 from CourseHero.com on 02-28-2022 04:23:23 GMT -06:00
https://www.coursehero.com/file/75224912/Laboratorul-4docx/
}
while (depozit.size()>=4) {
try {
wait();
catch (InterruptedException e) {
depozit.add(m);
System.out.print(depozit.get(depozit.size()-1)+", ");
depozit.add(n);
System.out.println(depozit.get(depozit.size()-1));
if(depozit.size()!=0){
System.out.println(" ");}
else{
notifyAll();
This study source was downloaded by 100000798432454 from CourseHero.com on 02-28-2022 04:23:23 GMT -06:00
https://www.coursehero.com/file/75224912/Laboratorul-4docx/
class Producer extends Thread{
Store store;
Producer(Store store){
this.store=store;
int a,b;
for(int i=0;i<2;i++)
{a = (int)(Math.random()*100);
while (a%2==0)
{a++;}
b = (int)(Math.random()*100);
while (a%2==0)
{a++;}
store.put(getName(),a,b);}
}}
Store store;
Consumer(Store store){
this.store=store;
{store.get(getName()); }
This study source was downloaded by 100000798432454 from CourseHero.com on 02-28-2022 04:23:23 GMT -06:00
https://www.coursehero.com/file/75224912/Laboratorul-4docx/
}}
This study source was downloaded by 100000798432454 from CourseHero.com on 02-28-2022 04:23:23 GMT -06:00
https://www.coursehero.com/file/75224912/Laboratorul-4docx/
Powered by TCPDF (www.tcpdf.org)