Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- public class Mostrador<T> {
- private LinkedList<Integer> bizcochos = new LinkedList<>();
- private LinkedList<Integer> facturas = new LinkedList<>();
- public Mostrador() {
- }
- public synchronized boolean noHayBizc() {
- if (bizcochos.size()<=0) return true;
- notifyAll();
- return false;
- }
- public synchronized boolean noHayFact() {
- if (facturas.size()<=0) return true;
- notifyAll();
- return false;
- }
- public synchronized void agregarBizcocho(int elemento) {
- bizcochos.addLast(elemento);
- notifyAll();
- }
- public synchronized void agregarFactura(int elemento) {
- facturas.addLast(elemento);
- notifyAll();
- }
- public synchronized int comprarBizcocho() {
- while(bizcochos.size()<=0) {
- try {
- wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- int elemento = bizcochos.removeFirst();
- notifyAll();
- return elemento;
- }
- public synchronized int comprarFactura() {
- while(facturas.size()<=0) {
- try {
- wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- int elemento = facturas.removeFirst();
- notifyAll();
- return elemento;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement