Alejandro_S_Mercado

Untitled

Sep 24th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | Source Code | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         ArrayList <Integer> lista=new ArrayList<Integer>();
  5.         int MAX_SIZE=5;
  6.         Random random=new Random();
  7.             int tiempoInicial=100;
  8.             int tiempoFinal=200;
  9.            
  10.             int consumidores=0;
  11.             int productores=0;
  12.        
  13.         while(true) {
  14.             int tiempoRetardo=random.nextInt((tiempoFinal-tiempoInicial)+1)+tiempoInicial;
  15.             int prodCons=random.nextInt(2); // 0 o 1
  16.            
  17.             try {
  18.                 Thread.sleep(tiempoRetardo);
  19.             } catch (InterruptedException e) {
  20.                 e.printStackTrace();
  21.             }
  22.             if(prodCons==0 ) {
  23.            
  24.                 Consumidor consumidorX=new Consumidor(lista,consumidores);
  25.                 consumidorX.start();
  26.                 consumidores++;
  27.             }
  28.             else if(prodCons==1 ) {
  29.  
  30.                 Productor productorX=new Productor(lista,productores,MAX_SIZE);
  31.                 productorX.start();
  32.                 productores++;
  33.             }
  34.         }
  35.        
  36.        
  37.  
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment