Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProductorFactura extends Thread{
- private ArrayList <Object> mostrador;
- private int num;
- private String[] types;
- private String type;
- private Random random;
- public ProductorFactura(ArrayList <Object> mostrador) {
- this.mostrador=mostrador;
- this.num=0;
- this.types=new String[]{"con chocolate","simple","con coco"};
- this.type="";
- this.random=new Random();
- }
- public void run() {
- while(true) {
- try {
- int timeProduction=random.nextInt(1300-1000)+1000;
- int typeRandom=random.nextInt(this.types.length);
- Thread.sleep(timeProduction);
- synchronized(mostrador) {
- this.num++;
- this.type=types[typeRandom];
- Factura factura=new Factura(this.num,this.type);
- mostrador.add(factura);
- mostrador.notifyAll();
- }
- }catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("Factura("+num+", "+this.type+")"+" en mostrador");
- }
- }
- }
- public class ProductorBizcocho extends Thread{
- private ArrayList <Object> mostrador;
- private int num;
- private String[] types;
- private String type;
- private Random random;
- public ProductorBizcocho(ArrayList <Object> mostrador) {
- this.mostrador=mostrador;
- this.num=0;
- this.types=new String[]{"Cuadrado","chato","relleno"};
- this.type="";
- this.random=new Random();
- }
- public void run() {
- while(true) {
- try {
- int timeProduction=random.nextInt(600-400)+400;
- int typeRandom=random.nextInt(this.types.length);
- Thread.sleep(timeProduction);
- synchronized(mostrador) {
- this.num++;
- this.type=types[typeRandom];
- Bizcocho bizcocho=new Bizcocho(this.num,this.type);
- mostrador.add(bizcocho);
- mostrador.notifyAll();
- }
- }catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("Bizcocho("+this.num+", "+this.type+") en mostrador");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment