/** * Create some pool. * @param num The number of pool. */ protected synchronized void addThreads(int num) { for(int i=0; i<num; i++) { addThread(); } }
/** * Remove the service thread from the pool. */ protected void remove() { terminated = true; boolean notify = false; synchronized(ThreadPool.this) { // System.out.println("readded: "+this); pool.remove(this); parked.remove(this); // System.out.println("thread terminating: "+this+" "+pool.size()+" "+parked.size()); if(!finished && pool.size()==0 && parked.size()==0) { finished = true; notify = true; // System.out.println("pool terminated: "+ThreadPool.this); } } if(notify) notifyFinishListeners(); }
ClassSearchPanel pan = new ClassSearchPanel(cl, tp!=null? tp: new ThreadPool());
addThreads(strategy.getWorkerCount());
boolean interfaces, boolean absclasses, boolean classes, boolean innerclasses) this.tp = tp==null? new ThreadPool(): tp;
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);
this.tp = tp==null? new ThreadPool(): tp; this.cl = cl==null? AutoCompleteCombo.class.getClassLoader(): cl; setEditable(true);