本文整理了Java中java.util.concurrent.ThreadPoolExecutor.getKeepAliveTime()
方法的一些代码示例,展示了ThreadPoolExecutor.getKeepAliveTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.getKeepAliveTime()
方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:getKeepAliveTime
[英]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.
[中]返回线程保持活动时间,即超过核心池大小的线程在终止前可能保持空闲的时间量。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public long getKeepAliveTime() {
return exec instanceof ThreadPoolExecutor ?
((ThreadPoolExecutor)exec).getKeepAliveTime(TimeUnit.MILLISECONDS) : -1;
}
代码示例来源:origin: jmxtrans/jmxtrans
@Override
public long getKeepAliveTimeSeconds() {
return executor.getKeepAliveTime(SECONDS);
}
代码示例来源:origin: wildfly/wildfly
public long getKeepAliveTime() {return condGet(p -> p.getKeepAliveTime(TimeUnit.MILLISECONDS), 0L);}
public void setKeepAliveTime(long time) {condSet(p -> p.setKeepAliveTime(time, TimeUnit.MILLISECONDS));}
代码示例来源:origin: springside/springside4
@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();
}
代码示例来源:origin: springside/springside4
@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();
}
}
代码示例来源:origin: kaaproject/kaa
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);
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
/**
* @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);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@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)));
}
代码示例来源:origin: camunda/camunda-bpm-platform
@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));
}
代码示例来源:origin: geotools/geotools
+ tpe.getMaximumPoolSize()
+ "\nkeep alive time "
+ tpe.getKeepAliveTime(TimeUnit.MILLISECONDS));
代码示例来源:origin: net.sf.corn/corn-exception
/**
* 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);
}
代码示例来源:origin: org.apache.ignite/ignite-core
/** {@inheritDoc} */
@Override public long getKeepAliveTime() {
return exec instanceof ThreadPoolExecutor ?
((ThreadPoolExecutor)exec).getKeepAliveTime(TimeUnit.MILLISECONDS) : -1;
}
代码示例来源:origin: org.gridgain/gridgain-core
/** {@inheritDoc} */
@Override public long getKeepAliveTime() {
assert exec != null;
return exec instanceof ThreadPoolExecutor ?
((ThreadPoolExecutor)exec).getKeepAliveTime(TimeUnit.MILLISECONDS) : -1;
}
代码示例来源:origin: org.wisdom-framework/wisdom-executors
/**
* 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);
}
代码示例来源:origin: co.paralleluniverse/galaxy
@Override
public long getKeepAliveTime() {
final ThreadPoolExecutor executor = getMonitored();
if (executor == null)
return -1;
return executor.getKeepAliveTime(TimeUnit.MILLISECONDS);
}
代码示例来源:origin: com.opentable.components/otj-executors
@Override
@ManagedAttribute
public long getKeepAliveTime()
{
return service.getKeepAliveTime(TimeUnit.MILLISECONDS);
}
代码示例来源:origin: jenkinsci/winstone
/**
* @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);
}
代码示例来源:origin: jpos/jPOS
public long getKeepAliveTimeMS() throws NotFoundException {
ThreadPoolExecutor executorService = getThreadPoolExecutor(getName(),
ThreadPoolExecutor.class);
return executorService.getKeepAliveTime(TimeUnit.MILLISECONDS);
}
代码示例来源:origin: com.proofpoint.platform/concurrent
@Managed
public String getKeepAliveTime()
{
return new Duration(threadPoolExecutor.getKeepAliveTime(NANOSECONDS), NANOSECONDS)
.convertToMostSuccinctTimeUnit()
.toString();
}
代码示例来源:origin: airlift/airlift
@Managed
public String getKeepAliveTime()
{
return new Duration(threadPoolExecutor.getKeepAliveTime(NANOSECONDS), NANOSECONDS)
.convertToMostSuccinctTimeUnit()
.toString();
}
内容来源于网络,如有侵权,请联系作者删除!