JUnit tests

This commit is contained in:
gwildor28
2016-04-17 14:46:52 +01:00
parent e821abdb1b
commit a2843297d8
9 changed files with 236 additions and 11 deletions
@@ -27,13 +27,29 @@ package com.iluwatar.semaphore;
*/
public class Semaphore implements Lock {
private final int licenses;
/**
* The number of concurrent resource accesses which are allowed.
*/
private int counter;
public Semaphore(int counter) {
this.counter = counter;
public Semaphore(int licenses) {
this.licenses = licenses;
this.counter = licenses;
}
/**
* Returns the number of licenses managed by the Semaphore
*/
public int getNumLicenses() {
return licenses;
}
/**
* Returns the number of available licenses
*/
public int getAvailableLicenses() {
return counter;
}
/**
@@ -52,8 +68,10 @@ public class Semaphore implements Lock {
* Method called by a thread to release the lock.
*/
public synchronized void release() {
counter = counter + 1;
notify();
if (counter < licenses) {
counter = counter + 1;
notify();
}
}
}