package ge.edu.freeuni.sdp.arkanoid.model;

import java.util.ArrayList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by nika on 4/2/16.
 */
public class DeathCountListener implements GobjDeathListener {

    private int _count;
    private ArrayList<LevelOverListener> _overListeners;
    private Lock _countLock;

    public DeathCountListener(int count) {
        _count = count;
        _overListeners = new ArrayList<>();
        _countLock = new ReentrantLock();
    }

    public void setLevelOverListener(LevelOverListener listener) {
        _overListeners.add(listener);
    }

    public void setCount(int count) {
        _countLock.lock();
        _count = count;
        _countLock.unlock();
    }

    public int getCount() {
        int res;
        _countLock.lock();
        res = _count;
        _countLock.unlock();
        return res;
    }

    @Override
    public void gobjDied(Gobj obj, String reason) {
        boolean notify;
        _countLock.lock();
        _count--;
        notify = (_count == 0);
        _countLock.unlock();

        if (notify)
            notifyAllLevelOver();
    }

    protected void notifyAllLevelOver() {
        _overListeners.forEach(LevelOverListener::levelOver);
    }

}

@@ -65,16 +65,66 @@
 ayList;%0A
+import java.util.concurrent.atomic.AtomicInteger;%0A
 import j
@@ -319,19 +319,29 @@
 private 
-int
+AtomicInteger
  _count;
@@ -401,37 +401,8 @@
 ers;
-%0A    private Lock _countLock;
 %0A%0A  
@@ -451,37 +451,56 @@
        _count = 
+new AtomicInteger(
 count
+)
 ;%0A        _overL
@@ -533,50 +533,8 @@
 ();%0A
-        _countLock = new ReentrantLock();%0A
     
@@ -704,446 +704,222 @@
 ount
-Lock.lock();%0A        _count = count;%0A        _countLock.unlock();%0A    %7D%0A%0A    public int getCount() %7B%0A        int res;%0A        _countLock.lock();%0A        res = _count;%0A        _countLock.unlock();%0A        return res;%0A    %7D%0A%0A    @Override%0A    public void gobjDied(Gobj obj, String reason) %7B%0A        boolean notify;%0A        _countLock.lock();%0A        _count--;%0A        notify = (_count == 0);%0A        _countLock.unlock();%0A%0A        if (notify
+.set(count);%0A    %7D%0A%0A    public int getCount() %7B%0A        return _count.get();%0A    %7D%0A%0A    @Override%0A    public void gobjDied(Gobj obj, String reason) %7B%0A        int value = _count.addAndGet(-1);%0A        if (value == 0
 )%0A  

Change DeathCountListener to use AtomicInteger