java.util.concurrent.ThreadPoolExecutor.setMaximumPoolSize()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中java.util.concurrent.ThreadPoolExecutor.setMaximumPoolSize()方法的一些代码示例,展示了ThreadPoolExecutor.setMaximumPoolSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.setMaximumPoolSize()方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:setMaximumPoolSize

ThreadPoolExecutor.setMaximumPoolSize介绍

[英]Sets the maximum allowed number of threads. This overrides any value set in the constructor. If the new value is smaller than the current value, excess existing threads will be terminated when they next become idle.
[中]设置允许的最大线程数。这将覆盖构造函数中设置的任何值。如果新值小于当前值,多余的现有线程将在下次空闲时终止。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the ThreadPoolExecutor's maximum pool size.
 * Default is {@code Integer.MAX_VALUE}.
 * <p><b>This setting can be modified at runtime, for example through JMX.</b>
 */
public void setMaxPoolSize(int maxPoolSize) {
  synchronized (this.poolSizeMonitor) {
    this.maxPoolSize = maxPoolSize;
    if (this.threadPoolExecutor != null) {
      this.threadPoolExecutor.setMaximumPoolSize(maxPoolSize);
    }
  }
}

代码示例来源:origin: org.springframework/spring-context

/**
 * Set the ThreadPoolExecutor's maximum pool size.
 * Default is {@code Integer.MAX_VALUE}.
 * <p><b>This setting can be modified at runtime, for example through JMX.</b>
 */
public void setMaxPoolSize(int maxPoolSize) {
  synchronized (this.poolSizeMonitor) {
    this.maxPoolSize = maxPoolSize;
    if (this.threadPoolExecutor != null) {
      this.threadPoolExecutor.setMaximumPoolSize(maxPoolSize);
    }
  }
}

代码示例来源:origin: apache/hbase

@Override
public void setMaxPoolSize(int newMaxSize) {
 pool.setMaximumPoolSize(newMaxSize);
}

代码示例来源:origin: wildfly/wildfly

public TP setThreadPoolMaxThreads(int size) {
  thread_pool_max_threads=size;
  if(thread_pool instanceof ThreadPoolExecutor)
    ((ThreadPoolExecutor)thread_pool).setMaximumPoolSize(size);
  return this;
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Sets the max number of threads the channel will use for processing messages. The channel
 * will automatically allocate new worker threads as the queue size grows, up to the defined
 * maximum. This lets the channel meet higher concurrency needs, but prevents too many threads
 * from being allocated, which decreases overall system performance.
 *
 * @param maxThreadCount the max number of threads that can be used by the channel.
 */
public void setMaxThreadCount(int maxThreadCount) {
  executor.setMaximumPoolSize(maxThreadCount);
}

代码示例来源:origin: mttkay/ignition

/**
 * @param numThreads
 *            the maximum number of threads that will be started to download images in parallel
 */
public void setThreadPoolSize(int numThreads) {
  executor.setMaximumPoolSize(numThreads);
}

代码示例来源:origin: wildfly/wildfly

public void setMaximumPoolSize(final int size) {
  if (size > getCorePoolSize()) {
    super.setMaximumPoolSize(size);
    super.setCorePoolSize(size);
  } else {
    super.setCorePoolSize(size);
    super.setMaximumPoolSize(size);
  }
}

代码示例来源:origin: apache/activemq

/**
 * Set the number of threads to be used for processing connections.  Defaults
 * to Integer.MAX_SIZE.  Set this value to be lower to reduce the
 * number of simultaneous connection attempts.  If not set then the maximum number of
 * threads will generally be controlled by the transport maxConnections setting:
 * {@link TcpTransportServer#setMaximumConnections(int)}.
 *<p>
 * Note that this setter controls two thread pools because connection attempts
 * require 1 thread to start processing the connection and another thread to read from the
 * socket and to detect the protocol. Two threads are needed because some transports
 * block on socket read so the first thread needs to be able to abort the second thread on timeout.
 * Therefore this setting will set each thread pool to the size passed in essentially giving
 * 2 times as many potential threads as the value set.
 *<p>
 * Both thread pools will close idle threads after a period of time
 * essentially allowing the thread pools to grow and shrink dynamically based on load.
 *
 * @see {@link TcpTransportServer#setMaximumConnections(int)}.
 * @param maxConnectionThreadPoolSize
 */
public void setMaxConnectionThreadPoolSize(int maxConnectionThreadPoolSize) {
  this.maxConnectionThreadPoolSize = maxConnectionThreadPoolSize;
  newConnectionExecutor.setCorePoolSize(maxConnectionThreadPoolSize);
  newConnectionExecutor.setMaximumPoolSize(maxConnectionThreadPoolSize);
  protocolDetectionExecutor.setCorePoolSize(maxConnectionThreadPoolSize);
  protocolDetectionExecutor.setMaximumPoolSize(maxConnectionThreadPoolSize);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public void setWorkThread(int workThread) {
  if (workThread == 0) {
    throw new IllegalArgumentException("workThread can not be zero!");
  }
  threadPoolExecutor.setMaximumPoolSize(workThread);
  threadPoolExecutor.setCorePoolSize(workThread);
  LOGGER.info("workThread update to {}", workThread);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public void setWorkThread(int workThread) {
  if (workThread == 0) {
    throw new IllegalArgumentException("workThread can not be zero!");
  }
  threadPoolExecutor.setMaximumPoolSize(workThread);
  threadPoolExecutor.setCorePoolSize(workThread);
  LOGGER.info("workThread update to {}", workThread);
}

代码示例来源:origin: wildfly/wildfly

public void    setMaxThreads(int size)               {condSet(p -> p.setMaximumPoolSize(size));}
public long    getKeepAliveTime()                    {return condGet(p -> p.getKeepAliveTime(TimeUnit.MILLISECONDS), 0L);}

代码示例来源:origin: apache/hbase

largeThreads);
if(this.longCompactions.getCorePoolSize() < largeThreads) {
 this.longCompactions.setMaximumPoolSize(largeThreads);
 this.longCompactions.setCorePoolSize(largeThreads);
} else {
 this.longCompactions.setCorePoolSize(largeThreads);
 this.longCompactions.setMaximumPoolSize(largeThreads);
     smallThreads);
if(this.shortCompactions.getCorePoolSize() < smallThreads) {
 this.shortCompactions.setMaximumPoolSize(smallThreads);
 this.shortCompactions.setCorePoolSize(smallThreads);
} else {
 this.shortCompactions.setCorePoolSize(smallThreads);
 this.shortCompactions.setMaximumPoolSize(smallThreads);
     splitThreads);
if(this.splits.getCorePoolSize() < splitThreads) {
 this.splits.setMaximumPoolSize(splitThreads);
 this.splits.setCorePoolSize(splitThreads);
} else {
 this.splits.setCorePoolSize(splitThreads);
 this.splits.setMaximumPoolSize(splitThreads);

代码示例来源:origin: apache/incubator-dubbo

threadPoolExecutor.setCorePoolSize(threads);
if (core == max) {
  threadPoolExecutor.setMaximumPoolSize(threads);
threadPoolExecutor.setMaximumPoolSize(threads);
if (core == max) {
  threadPoolExecutor.setCorePoolSize(threads);

代码示例来源:origin: apache/incubator-dubbo

threadPoolExecutor.setCorePoolSize(threads);
if (core == max) {
  threadPoolExecutor.setMaximumPoolSize(threads);
threadPoolExecutor.setMaximumPoolSize(threads);
if (core == max) {
  threadPoolExecutor.setCorePoolSize(threads);

代码示例来源:origin: apache/hbase

private ThreadPoolExecutor disableHandlers(RpcScheduler scheduler) {
 ThreadPoolExecutor rpcExecutor=null;
 try {
  Field ExecutorField = scheduler.getClass().getDeclaredField("executor");
  ExecutorField.setAccessible(true);
  scheduler.start();
  rpcExecutor = (ThreadPoolExecutor) ExecutorField.get(scheduler);
  rpcExecutor.setMaximumPoolSize(1);
  rpcExecutor.allowCoreThreadTimeOut(true);
  rpcExecutor.setCorePoolSize(0);
  rpcExecutor.setKeepAliveTime(1, TimeUnit.MICROSECONDS);
  // Wait for 2 seconds, so that idle threads will die
  Thread.sleep(2000);
 } catch (NoSuchFieldException e) {
  LOG.error("No such field exception:"+e);
 } catch (IllegalAccessException e) {
  LOG.error("Illegal access exception:"+e);
 } catch (InterruptedException e) {
  LOG.error("Interrupted exception:"+e);
 }
 return rpcExecutor;
}

代码示例来源:origin: PipelineAI/pipeline

private void touchConfig() {
  final int dynamicCoreSize = properties.coreSize().get();
  final int configuredMaximumSize = properties.maximumSize().get();
  int dynamicMaximumSize = properties.actualMaximumSize();
  final boolean allowSizesToDiverge = properties.getAllowMaximumSizeToDivergeFromCoreSize().get();
  boolean maxTooLow = false;
  if (allowSizesToDiverge && configuredMaximumSize < dynamicCoreSize) {
    //if user sets maximum < core (or defaults get us there), we need to maintain invariant of core <= maximum
    dynamicMaximumSize = dynamicCoreSize;
    maxTooLow = true;
  }
  // In JDK 6, setCorePoolSize and setMaximumPoolSize will execute a lock operation. Avoid them if the pool size is not changed.
  if (threadPool.getCorePoolSize() != dynamicCoreSize || (allowSizesToDiverge && threadPool.getMaximumPoolSize() != dynamicMaximumSize)) {
    if (maxTooLow) {
      logger.error("Hystrix ThreadPool configuration for : " + metrics.getThreadPoolKey().name() + " is trying to set coreSize = " +
          dynamicCoreSize + " and maximumSize = " + configuredMaximumSize + ".  Maximum size will be set to " +
          dynamicMaximumSize + ", the coreSize value, since it must be equal to or greater than the coreSize value");
    }
    threadPool.setCorePoolSize(dynamicCoreSize);
    threadPool.setMaximumPoolSize(dynamicMaximumSize);
  }
  threadPool.setKeepAliveTime(properties.keepAliveTimeMinutes().get(), TimeUnit.MINUTES);
}

代码示例来源:origin: com.zaxxer/HikariCP

addConnectionExecutor.setMaximumPoolSize(Runtime.getRuntime().availableProcessors());
addConnectionExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
addConnectionExecutor.setMaximumPoolSize(1);
addConnectionExecutor.setCorePoolSize(1);

代码示例来源:origin: geoserver/geoserver

|| (queue instanceof SynchronousQueue && queueType == QueueType.DIRECT)) {
executor.setCorePoolSize(coverageAccess.getCorePoolSize());
executor.setMaximumPoolSize(coverageAccess.getMaxPoolSize());
executor.setKeepAliveTime(
    coverageAccess.getKeepAliveTime(), TimeUnit.MILLISECONDS);

代码示例来源:origin: igniterealtime/Openfire

( (ThreadPoolExecutor) executorFilter.getExecutor()).setMaximumPoolSize( ( configuration.getMaxThreadPoolSize() ) );

代码示例来源:origin: org.eclipse.jetty/jetty-util

@Override
public void setMaxThreads(int threads)
{
  if (_budget!=null)
    _budget.check(threads);
  _executor.setCorePoolSize(threads);
  _executor.setMaximumPoolSize(threads);
}

相关文章

ThreadPoolExecutor类方法