/** {@inheritDoc} */ @Override public long getKeepAliveTime() { return exec instanceof ThreadPoolExecutor ? ((ThreadPoolExecutor)exec).getKeepAliveTime(TimeUnit.MILLISECONDS) : -1; }
@Override public long getKeepAliveTimeSeconds() { return executor.getKeepAliveTime(SECONDS); }
public long getKeepAliveTime() {return condGet(p -> p.getKeepAliveTime(TimeUnit.MILLISECONDS), 0L);} public void setKeepAliveTime(long time) {condSet(p -> p.setKeepAliveTime(time, TimeUnit.MILLISECONDS));}
@Test public void cachedPool() { ThreadPoolExecutor singlePool = ThreadPoolBuilder.cachedPool().build(); assertThat(singlePool.getCorePoolSize()).isEqualTo(0); assertThat(singlePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE); assertThat(singlePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(10); assertThat(singlePool.getQueue()).isInstanceOf(SynchronousQueue.class); singlePool.shutdown(); ThreadPoolExecutor sizeablePool = ThreadPoolBuilder.cachedPool().setMinSize(10).setMaxSize(100) .setKeepAliveSecs(20).build(); assertThat(sizeablePool.getCorePoolSize()).isEqualTo(10); assertThat(sizeablePool.getMaximumPoolSize()).isEqualTo(100); assertThat(sizeablePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(20); sizeablePool.shutdown(); ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.cachedPool().setThreadNamePrefix("cachedPool") .build(); Thread thread = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() { @Override public void run() { } }); assertThat(thread.getName()).startsWith("cachedPool"); fixPoolWithNamePrefix.shutdown(); }
@Test public void quequablePool() { ThreadPoolExecutor singlePool = ThreadPoolBuilder.queuableCachedPool().build(); assertThat(singlePool.getCorePoolSize()).isEqualTo(0); assertThat(singlePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE); assertThat(singlePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(10); assertThat(singlePool.getQueue()).isInstanceOf(ControllableQueue.class); singlePool.shutdown(); ThreadPoolExecutor sizeablePool = ThreadPoolBuilder.queuableCachedPool().setMinSize(10).setMaxSize(100) .setKeepAliveSecs(20).build(); assertThat(sizeablePool.getCorePoolSize()).isEqualTo(10); assertThat(sizeablePool.getMaximumPoolSize()).isEqualTo(100); assertThat(sizeablePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(20); sizeablePool.shutdown(); ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.queuableCachedPool() .setThreadNamePrefix("queuableCachedPool").build(); Thread thread = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() { @Override public void run() { } }); assertThat(thread.getName()).startsWith("queuableCachedPool"); fixPoolWithNamePrefix.shutdown(); } }
private void checkThreadPoolExecutorServices(ExecutorService executorService, int minThreads, int maxThreads, int maxIdleMilliseconds, String executorName) { ThreadPoolExecutor threadPoolExecutor; int actualMinThreads; int actualMaxThreads; int actualMaxThreadIdleMilliseconds; Assert.assertTrue(executorService instanceof ThreadPoolExecutor); threadPoolExecutor = (ThreadPoolExecutor) executorService; actualMinThreads = threadPoolExecutor.getCorePoolSize(); actualMaxThreads = threadPoolExecutor.getMaximumPoolSize(); actualMaxThreadIdleMilliseconds = (int) threadPoolExecutor.getKeepAliveTime(TimeUnit.MILLISECONDS); Assert.assertEquals("Wrong " + executorName + " executor core pool size", minThreads, actualMinThreads); Assert.assertEquals("Wrong " + executorName + " executor maximum pool size", maxThreads, actualMaxThreads); Assert.assertEquals("Wrong " + executorName + " executor maximum pool size", maxIdleMilliseconds, actualMaxThreadIdleMilliseconds); }
/** * @return the maximum thread idle time in ms. * @see #setIdleTimeout(int) */ @ManagedAttribute("maximum time a thread may be idle in ms") public int getIdleTimeout() { return (int)_executor.getKeepAliveTime(TimeUnit.MILLISECONDS); }
@Test public void performOperationStepWithPropertiesInXml() { Map<String, String> properties = new HashMap<String, String>(); String queueSize = "5"; String corePoolSize = "12"; String maxPoolSize = "20"; String keepAliveTime = "100"; properties.put(JobExecutorXml.CORE_POOL_SIZE, corePoolSize ); properties.put(JobExecutorXml.KEEP_ALIVE_TIME, keepAliveTime); properties.put(JobExecutorXml.MAX_POOL_SIZE, maxPoolSize); properties.put(JobExecutorXml.QUEUE_SIZE, queueSize); jobExecutorXml.setProperties(properties); step.performOperationStep(deploymentOperation); PlatformService<JmxManagedThreadPool> service = container.getService(getObjectNameForExecutor()); ThreadPoolExecutor executor = service.getValue().getThreadPoolExecutor(); //since no jobs will start, remaining capacity is sufficent to check the size assertThat(executor.getQueue().remainingCapacity(), is(Integer.parseInt(queueSize))); assertThat(executor.getCorePoolSize(), is(Integer.parseInt(corePoolSize))); assertThat(executor.getMaximumPoolSize(), is(Integer.parseInt(maxPoolSize))); assertThat(executor.getKeepAliveTime(TimeUnit.MILLISECONDS), is(Long.parseLong(keepAliveTime))); }
@Test public void performOperationStepWithDefaultProperties() { Map<String, String> properties = new HashMap<String, String>(); jobExecutorXml.setProperties(properties); step.performOperationStep(deploymentOperation); PlatformService<JmxManagedThreadPool> service = container.getService(getObjectNameForExecutor()); ThreadPoolExecutor executor = service.getValue().getThreadPoolExecutor(); //since no jobs will start, remaining capacity is sufficent to check the size assertThat(executor.getQueue().remainingCapacity(), is(3)); assertThat(executor.getCorePoolSize(), is(3)); assertThat(executor.getMaximumPoolSize(), is(10)); assertThat(executor.getKeepAliveTime(TimeUnit.MILLISECONDS), is(0L)); }
+ tpe.getMaximumPoolSize() + "\nkeep alive time " + tpe.getKeepAliveTime(TimeUnit.MILLISECONDS));
/** * Returns the thread keep-alive time, which is the amount of time that * threads in excess of the core pool size may remain idle before being * terminated. * * @param unit * the desired time unit of the result * @return the time limit */ public static long getKeepAliveTime(TimeUnit unit) { return executor.getKeepAliveTime(unit); }
/** {@inheritDoc} */ @Override public long getKeepAliveTime() { return exec instanceof ThreadPoolExecutor ? ((ThreadPoolExecutor)exec).getKeepAliveTime(TimeUnit.MILLISECONDS) : -1; }
/** {@inheritDoc} */ @Override public long getKeepAliveTime() { assert exec != null; return exec instanceof ThreadPoolExecutor ? ((ThreadPoolExecutor)exec).getKeepAliveTime(TimeUnit.MILLISECONDS) : -1; }
/** * Returns the thread keep-alive time, which is the amount of time * that threads in excess of the core pool size may remain * idle before being terminated. * * @param unit the desired time unit of the result * @return the time limit */ @Override public synchronized long getKeepAliveTime(TimeUnit unit) { return internalPool.getKeepAliveTime(unit); }
@Override public long getKeepAliveTime() { final ThreadPoolExecutor executor = getMonitored(); if (executor == null) return -1; return executor.getKeepAliveTime(TimeUnit.MILLISECONDS); }
@Override @ManagedAttribute public long getKeepAliveTime() { return service.getKeepAliveTime(TimeUnit.MILLISECONDS); }
/** * @return the maximum thread idle time in ms. * @see #setIdleTimeout(int) */ @ManagedAttribute("maximum time a thread may be idle in ms") public int getIdleTimeout() { return (int)_executor.getKeepAliveTime(TimeUnit.MILLISECONDS); }
public long getKeepAliveTimeMS() throws NotFoundException { ThreadPoolExecutor executorService = getThreadPoolExecutor(getName(), ThreadPoolExecutor.class); return executorService.getKeepAliveTime(TimeUnit.MILLISECONDS); }
@Managed public String getKeepAliveTime() { return new Duration(threadPoolExecutor.getKeepAliveTime(NANOSECONDS), NANOSECONDS) .convertToMostSuccinctTimeUnit() .toString(); }
@Managed public String getKeepAliveTime() { return new Duration(threadPoolExecutor.getKeepAliveTime(NANOSECONDS), NANOSECONDS) .convertToMostSuccinctTimeUnit() .toString(); }