Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
public class ConsumidorCliente extends Thread{ private ArrayList
mostrador; private int numCliente; private Random random; public ConsumidorCliente(ArrayList
mostrador,int numCliente) { this.mostrador=mostrador; this.numCliente=numCliente; this.random=new Random(); } public void run() { try { int timeConsumition=random.nextInt(400-200)+200; System.out.println("El cliente("+this.numCliente+") está comprando"); boolean waitBizcocho = false; boolean waitFactura = false; Bizcocho b = null; Factura f = null; synchronized(mostrador) { while(true) { if(mostrador.isEmpty()) { System.out.println("El mostrador está vacío"); System.out.println("El cliente("+this.numCliente+") debe esperar"); mostrador.wait(); } else { for (Object e : mostrador) { if (e instanceof Bizcocho && b == null) { b = (Bizcocho) e; } if (e instanceof Factura && f == null) { f = (Factura) e; } } if (b != null && f != null) break; if (b == null && !waitBizcocho) { System.out.println("El cliente(" + numCliente + ") debe esperar por un bizcocho"); waitBizcocho = true; } if (f == null && !waitFactura) { System.out.println("El cliente(" + numCliente + ") debe esperar por una factura"); waitFactura = true; } mostrador.wait(); } } Thread.sleep(timeConsumition); mostrador.remove(b); mostrador.remove(f); System.out.println("El cliente(" + numCliente + ") ha tomado el bizcocho(" + b.getNumBizcocho() + ", " + b.getTipoBizcocho() + ")"); System.out.println("El cliente(" + numCliente + ") ha tomado la factura(" + f.getNumFactura() + ", " + f.getTipoFactura() + ")"); System.out.println("El cliente(" + numCliente + ") se retiró del local."); } } catch (InterruptedException e) { e.printStackTrace(); } } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)