Facebook
From Baby Cat, 4 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 233
  1. public class Konsument extends Thread {
  2.  
  3.     private String id;
  4.     private Bufor buff;
  5.     private int powt;
  6.  
  7.     public Konsument(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.             if(buff.check()){
  16.                 break;
  17.             }
  18.             String temp = buff.get();
  19.             if(temp != "-1")
  20.                 System.out.println("[" + this.id + ", " + i + "] >> " + temp);
  21.             else
  22.                 break;
  23.             try {
  24.                 sleep((int) (Math.random() * 11) + 2);
  25.             } catch (InterruptedException e) {
  26.             }
  27.  
  28.         }
  29.     }
  30. }