public void run() { while(true) { try { /*Object item =*/ queue.dequeue(); // Object item = queue.take(); // System.out.println("Processing: "+item); stat[1] = Math.max(queue.size(), stat[1]); if(queue.size()==0) { stat[0]++; if(queue.size()==0 && stat[2]!=0) { System.out.println("Queue is now empty."); break; } } } catch(Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); throw new RuntimeException(sw.toString()); } } } }).start();
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);