Advertisement
Joaquin_Hidalgo

GenerarCliente

Sep 18th, 2024 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. package punto_2;
  2.  
  3. import java.util.Random;
  4.  
  5. public class GenerarCliente extends Thread {
  6.     private Buffer buffer;
  7.     private final int maxTiempo = 1500;
  8.     private final int minTiempo = 800;
  9.  
  10.     public GenerarCliente(Buffer b) {
  11.         this.buffer = b;
  12.     }
  13.  
  14.     public void run() {
  15.         Random r = new Random();
  16.         while (true) {
  17.             int tiempo = r.nextInt((maxTiempo - minTiempo) + 1) + minTiempo;
  18.             try {
  19.                 sleep(tiempo);
  20.             } catch (InterruptedException e) {
  21.                 e.printStackTrace();
  22.             }
  23.             Thread cliente = new Cliente(this.buffer);
  24.             cliente.start();
  25.         }
  26.     }
  27.  
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement