parent
4ca362c163
commit
2e523915f0
@ -0,0 +1,13 @@
|
|||||||
|
public class Customer implements Runnable {
|
||||||
|
private final PastryShop shop;
|
||||||
|
|
||||||
|
public Customer(PastryShop shop) {
|
||||||
|
this.shop = shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//TODO
|
||||||
|
shop.get();
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,12 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello, threads!");
|
PastryShop shop = new PastryShop();
|
||||||
|
|
||||||
|
Thread producer1 = new Thread(new PastryChef(shop));
|
||||||
|
Thread consumer1 = new Thread(new Customer(shop));
|
||||||
|
/*
|
||||||
|
producer1.start();
|
||||||
|
consumer1.start();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
public class Pastry {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "I'm a pastry";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
public class PastryChef implements Runnable {
|
||||||
|
private final PastryShop shop;
|
||||||
|
|
||||||
|
public PastryChef(PastryShop shop) {
|
||||||
|
this.shop = shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//TODO
|
||||||
|
shop.put(new Pastry());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PastryShop {
|
||||||
|
private final List<Pastry> stock = new ArrayList<>();
|
||||||
|
|
||||||
|
int head = 0, tail = 0; // probably wrong
|
||||||
|
|
||||||
|
public boolean put(Pastry pastry) {
|
||||||
|
//TODO
|
||||||
|
stock.add(tail, pastry);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pastry get() {
|
||||||
|
//TODO
|
||||||
|
return stock.get(head);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStock() {
|
||||||
|
return stock.size();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue