/** * {@inheritDoc} */ @Override public MonitoringConfig<ThreadPoolProbe> getMonitoringConfig() { return pool.getMonitoringConfig(); } }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return pool.awaitTermination(timeout, unit); }
@Override public void execute(Runnable r) { pool.execute(r); }
/** * {@inheritDoc} */ @Override protected void onRegister(GrizzlyJmxManager mom, GmbalMBean bean) { threadPool.getMonitoringConfig().addProbes(probe); totalAllocatedThreadCount.set(threadPool.getSize()); // set the initial value }
protected void doWork() { final Thread thread = t; while (true) { try { Thread.interrupted(); final Runnable r = getTask(); if (r == poison || r == null) { return; } onTaskDequeued(r); Throwable error = null; try { beforeExecute(this, thread, r); //inside try. to ensure balance r.run(); onTaskCompletedEvent(r); } catch (Exception e) { error = e; } finally { afterExecute(this, thread, r, error); } } catch (Exception ignore) { } } }
/** * Sets the {@link ThreadPoolConfig} * @param config * @return returns {@link GrizzlyExecutorService} */ public GrizzlyExecutorService reconfigure(ThreadPoolConfig config) { synchronized (statelock) { //TODO: only create new pool if old one cant be runtime config // for the needed state change(s). final AbstractThreadPool oldpool = this.pool; if (config.getQueue() == oldpool.getQueue()) { config.setQueue(null); } setImpl(config); AbstractThreadPool.drain(oldpool.getQueue(), this.pool.getQueue()); oldpool.shutdown(); } return this; }
@Override public String getJmxName() { return threadPool.getConfig().getPoolName(); }
protected void poisonAll() { int size = Math.max(config.getMaxPoolSize(), workers.size()) * 4 / 3; final Queue<Runnable> q = getQueue(); while (size-- > 0) { q.offer(poison); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(256); sb.append(getClass().getSimpleName()); sb.append(" config: [").append(config.toString()).append("]\r\n"); sb.append(", is-shutdown=").append(isShutdown()); return sb.toString(); }
config.setThreadFactory(getDefaultThreadFactory());
protected void doWork() { final Thread thread = t; while (true) { try { Thread.interrupted(); final Runnable r = getTask(); if (r == poison || r == null) { return; } onTaskDequeued(r); Throwable error = null; try { beforeExecute(this, thread, r); //inside try. to ensure balance r.run(); onTaskCompletedEvent(r); } catch (Exception e) { error = e; } finally { afterExecute(this, thread, r, error); } } catch (Exception ignore) { } } }
/** * Sets the {@link ThreadPoolConfig} * @param config * @return returns {@link GrizzlyExecutorService} */ public GrizzlyExecutorService reconfigure(ThreadPoolConfig config) { synchronized (statelock) { //TODO: only create new pool if old one cant be runtime config // for the needed state change(s). final AbstractThreadPool oldpool = this.pool; if (config.getQueue() == oldpool.getQueue()) { config.setQueue(null); } setImpl(config); AbstractThreadPool.drain(oldpool.getQueue(), this.pool.getQueue()); oldpool.shutdown(); } return this; }
@Override public String getJmxName() { return threadPool.getConfig().getPoolName(); }
protected void poisonAll() { int size = Math.max(config.getMaxPoolSize(), workers.size()) * 4 / 3; final Queue<Runnable> q = getQueue(); while (size-- > 0) { q.offer(poison); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(256); sb.append(getClass().getSimpleName()); sb.append(" config: [").append(config.toString()).append("]\r\n"); sb.append(", is-shutdown=").append(isShutdown()); return sb.toString(); }
config.setThreadFactory(getDefaultThreadFactory());
/** * {@inheritDoc} */ @Override protected void onRegister(GrizzlyJmxManager mom, GmbalMBean bean) { threadPool.getMonitoringConfig().addProbes(probe); totalAllocatedThreadCount.set(threadPool.getSize()); // set the initial value }
protected void doWork() { final Thread thread = t; while (true) { try { Thread.interrupted(); final Runnable r = getTask(); if (r == poison || r == null) { return; } onTaskDequeued(r); Throwable error = null; try { beforeExecute(this, thread, r); //inside try. to ensure balance r.run(); onTaskCompletedEvent(r); } catch (Exception e) { error = e; } finally { afterExecute(this, thread, r, error); } } catch (Exception ignore) { } } }
/** * Sets the {@link ThreadPoolConfig} * @param config * @return returns {@link GrizzlyExecutorService} */ public GrizzlyExecutorService reconfigure(ThreadPoolConfig config) { synchronized (statelock) { //TODO: only create new pool if old one cant be runtime config // for the needed state change(s). final AbstractThreadPool oldpool = this.pool; if (config.getQueue() == oldpool.getQueue()) { config.setQueue(null); } setImpl(config); AbstractThreadPool.drain(oldpool.getQueue(), this.pool.getQueue()); oldpool.shutdown(); } return this; }
@Override public void onTaskCancelEvent(AbstractThreadPool threadPool, Runnable task) { // when dequeued task is cancelled - we have to "return" the thread, that // we marked as dispatched from the pool grizzlyMonitoring.getThreadPoolProbeProvider().threadReturnedToPoolEvent( monitoringId, threadPool.getConfig().getPoolName(), Thread.currentThread().getId()); }