Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- ArrayList <Integer> lista=new ArrayList<Integer>();
- Random random=new Random();
- int tiempoInicial=100;
- int tiempoFinal=200;
- int consumidores=0;
- int productores=0;
- for(int i=0; i<20;i++) {
- int tiempoRetardo=random.nextInt((tiempoFinal-tiempoInicial)+1)+tiempoInicial;
- int prodCons=random.nextInt(2); // 0 o 1
- try {
- Thread.sleep(tiempoRetardo);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- if(prodCons==0 && consumidores<10) {
- Consumidor consumidorX=new Consumidor(lista,consumidores);
- consumidorX.start();
- consumidores++;
- }
- else if(prodCons==1 && productores<10) {
- Productor productorX=new Productor(lista,productores);
- productorX.start();
- productores++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment