/** * */ protected synchronized void addThread() { // System.out.println("parked: "+parked.size()); if(!parked.isEmpty()) { ServiceThread thread = parked.remove(0); synchronized(thread) { ((ServiceThread)thread).notified = true; thread.notify(); } } else { ServiceThread thread = new ServiceThread(); // Thread gets daemon state of parent, i.e. thread daemon state would // depend on called thread, which is not desired. thread.setDaemon(daemon); // thread.setDaemon(false); pool.add(thread); thread.start(); // System.out.println("pool: "+toString()+" "+pool.size()); } }
/** * The task for a given thread. */ protected synchronized Runnable getTask(Thread thread) { Runnable ret = null; if(thread instanceof ServiceThread) { ret = ((ServiceThread)thread).getTask(); } return ret; }