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>();
- int MAX_SIZE=5;
- Random random=new Random();
- int tiempoInicial=100;
- int tiempoFinal=200;
- int consumidores=0;
- int productores=0;
- while(true) {
- 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 ) {
- Consumidor consumidorX=new Consumidor(lista,consumidores);
- consumidorX.start();
- consumidores++;
- }
- else if(prodCons==1 ) {
- Productor productorX=new Productor(lista,productores,MAX_SIZE);
- productorX.start();
- productores++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment