Facebook
From Bistre Tamarin, 5 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 201
  1. public class Producent extends Thread
  2. {
  3.     private String id;
  4.     private Bufor buff;
  5.     private int powt;
  6.  
  7.     public Producent(String _id, Bufor _buff, int _powt) {
  8.         this.id = _id;
  9.         this.buff = _buff;
  10.         this.powt = _powt;
  11.     }
  12.  
  13.     public void run()
  14.     { for (int i = 0; i < this.powt; i++)
  15.     {
  16.         synchronized (buff) {
  17.             String in = "Dana = [" + this.id + ", " + i + ", " + (int) (Math.random() * 100) + "]";
  18.             buff.add(in);
  19.             //System.out.println("[" + this.id + ", " + i + "] >> " + in);
  20.             System.out.println(in);
  21.             try {
  22.                 sleep((int) (Math.random() * 10) + 1);
  23.             } catch (InterruptedException e) {
  24.             }
  25.         }
  26.     }
  27.     }
  28. }