Advertisement
RemigiuszP

Producent.java

Apr 6th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package rploetz.umk;
  2.  
  3. import java.util.Random;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6.  
  7. public class Producent implements Runnable
  8. {
  9.     private Queue q;
  10.  
  11.     public Producent(Queue my_q)
  12.     {
  13.         q = my_q;
  14.     }
  15.  
  16.     public void run()
  17.     {
  18.         Random r = new Random();
  19.  
  20.         while(true)
  21.         {
  22.             try
  23.             {
  24.                 Thread.sleep(3000);
  25.             }
  26.             catch (InterruptedException ex)
  27.             {
  28.                 Logger.getLogger(Producent.class.getName()).log(Level.SEVERE, (String)null);
  29.             }
  30.  
  31.             int element = r.nextInt();
  32.  
  33.             System.out.println("Wstawiam: " + element);
  34.  
  35.             q.put(element);
  36.             q.licznik++;
  37.  
  38.  
  39.         }
  40.     }
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement