@Override
        public void run() {
            while (true) {
                synchronized(monitor){
                    if(maxSize ==0){
                        isExecuting = false;
                        break;
                    }
                }
                while (waitingThreads.size() > 0) {
                    synchronized(monitor){
                        if(maxSize ==0){
                            isExecuting = false;
                            break;
                        }
                    }
                    if (currentSize < maxSize) {
                        currentSize++;
                        Runnable run = waitingThreads.poll();
                        RunnableThreads r = new RunnableThreads(run);
                        threadPool.run(r);
                    }
                }
                synchronized (monitor) {
                    if (waitingThreads.size() == 0) {
                        isExecuting = false;
                        break;
                    }
                }
//              System.out.println("Looping");
            }
        }
Facebook interview question
Implement a non block run which takes as many runnables as given but only
runs a specified number of threads.
You can also update maxSize in between which will change number of threads executing
http://tutorials.jenkov.com/java-concurrency/thread-pools.html
src/com/interview/multithreaded/ThreadPoolImpl.java