public void run() { synchronized(ThreadPool.this) { // If there are tasks and the last served task is too long ago if(running && tasks.size()>0) { Runnable task = tasks.peek(); Long start = enqueuetimes.get(task); if(start!=null && strategy.getCapacity()==0 && start.longValue()+maxwait<System.currentTimeMillis()) { addThreads(5); strategy.workersAdded(5); // System.out.println("Added threads due to starving task in queue: "+task+", "+strategy+", pool="+pool.size()+", parked="+parked.size()+", tasks="+tasks.size()); // System.out.println(tasks); } } } } }, maxwait, maxwait);