/** * @param name Name of this thread pool to use when naming threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name = name; }
/** * Set the number of reserved threads. * * @param reservedThreads number of reserved threads or -1 for heuristically determined * @see #getReservedThreads */ public void setReservedThreads(int reservedThreads) { if (isRunning()) throw new IllegalStateException(getState()); _reservedThreads = reservedThreads; }
/** * Blocks until the thread pool is {@link LifeCycle#stop stopped}. */ @Override public void join() throws InterruptedException { synchronized (_joinLock) { while (isRunning()) _joinLock.wait(); } while (isStopping()) Thread.sleep(1); }
private boolean startThreads(int threadsToStart) { while (threadsToStart > 0 && isRunning()) { int threads = _threadsStarted.get(); if (threads >= _maxThreads) return false; if (!_threadsStarted.compareAndSet(threads, threads + 1)) continue; boolean started = false; try { Thread thread = newThread(_runnable); thread.setDaemon(isDaemon()); thread.setPriority(getThreadsPriority()); thread.setName(_name + "-" + thread.getId()); _threads.add(thread); _lastShrink.set(System.nanoTime()); thread.start(); started = true; --threadsToStart; } finally { if (!started) _threadsStarted.decrementAndGet(); } } return true; }
@Override public void execute(Runnable job) { if (LOG.isDebugEnabled()) LOG.debug("queue {}",job); if (!isRunning() || !_jobs.offer(job)) { LOG.warn("{} rejected {}", this, job); throw new RejectedExecutionException(job.toString()); } else { // Make sure there is at least one thread executing the job. if (getThreads() == 0) startThreads(1); } }
/** * @param name Name of the BoundedThreadPool to use when naming Threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name= name; }
/** * @param max job queue size */ public void setMaxQueued(int max) { if (isRunning()) throw new IllegalStateException("started"); _maxQueued=max; }
/** * @param name Name of the BoundedThreadPool to use when naming Threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name = name; }
/** * @param name Name of the BoundedThreadPool to use when naming Threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name= name; }
/** * @param max job queue size */ public void setMaxQueued(int max) { if (isRunning()) throw new IllegalStateException("started"); _maxQueued=max; }
/** * @param max job queue size */ public void setMaxQueued(int max) { if (isRunning()) throw new IllegalStateException("started"); _maxQueued=max; }
/** * @param name Name of the BoundedThreadPool to use when naming Threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name= name; }
/** * @param name Name of the BoundedThreadPool to use when naming Threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name = name; }
/** * @param max job queue size */ public void setMaxQueued(int max) { if (isRunning()) throw new IllegalStateException("started"); _maxQueued=max; }
/** * @param name Name of the BoundedThreadPool to use when naming Threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name= name; }
/** * @param name Name of this thread pool to use when naming threads. */ public void setName(String name) { if (isRunning()) throw new IllegalStateException("started"); _name = name; }
@Override public boolean dispatch(Runnable job) { LOG.debug("{} dispatched {}", this, job); return isRunning() && _jobs.offer(job); }
@Override public boolean dispatch(Runnable job) { LOG.debug("{} dispatched {}", this, job); return isRunning() && _jobs.offer(job); }
/** * Blocks until the thread pool is {@link LifeCycle#stop stopped}. */ public void join() throws InterruptedException { synchronized (_joinLock) { while (isRunning()) _joinLock.wait(); } while (isStopping()) Thread.sleep(1); }