package ru.job4j.waitNotifyNotifyAll;

/**
 * Class ThreadPool.
 * @author Andrey Kustov
 * @version $1.0$
 * @since 02.08.2017
 */
public class ThreadPool {
    /**
     * lock.
     */
    private final Object lock = new Object();
    /**
     * threads.
     */
    private int freeThreads;

    /**
     * constructor.
     * @param freeThreads threads.
     */
    public ThreadPool(int freeThreads) {
        this.freeThreads = freeThreads;
    }

    /**
     * add new work.
     */
    public void add() {
        synchronized (this.lock) {
            while (freeThreads == 0) {
                try {
                    this.lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("do some work...");
        }
    }
}
