Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package f2015.ex4;
- import java.util.concurrent.locks.Lock;
- import java.util.concurrent.locks.ReentrantLock;
- class Mzareuli extends Thread {
- private int capacity;
- private Salobie salobie;
- int curCap;
- ReentrantLock lock;
- ReentrantLock intLock;
- Mzareuli(int cap, Salobie s) {
- capacity = cap;
- salobie = s;
- curCap = 0;
- lock = new ReentrantLock();
- intLock = new ReentrantLock();
- }
- // 1. თუკი გაქვს ადგილი და შეკვეთა არის მაშინ აიღე ის შემომავალი სინიდან
- // 2. გააკეთე ლობიო
- public void run() {
- while (true) {
- try {
- Salobie.condLock.lock();
- intLock.lock();
- while (curCap >= capacity || salobie.in.size() == 0) {
- Salobie.condLock.unlock();
- intLock.unlock();
- salobie.in.wait();
- intLock.lock();
- Salobie.condLock.lock();
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- Lobio l = (Lobio) salobie.in.remove(0);
- intLock.unlock();
- Salobie.condLock.unlock();
- l.cookMe(this);
- intLock.lock();
- curCap++;
- intLock.unlock();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement