当前位置: 首页>>代码示例>>Java>>正文


Java ThreadPoolExecutor.getCorePoolSize方法代码示例

本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.getCorePoolSize方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.getCorePoolSize方法的具体用法?Java ThreadPoolExecutor.getCorePoolSize怎么用?Java ThreadPoolExecutor.getCorePoolSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.getCorePoolSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testingOnlyPostEvent

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public void testingOnlyPostEvent ( MultiValueMap<String, String> formParams )
		throws Exception {

	// Support for LT. do not blow through queue
	if ( numSent++ % 1000 == 0 ) {
		logger.info( "Messages sent: " + numSent + " backlog: " + eventPostQueue.size() );
	}

	ThreadPoolExecutor pool = (ThreadPoolExecutor) eventPostPool;
	if ( eventPostQueue.size() > 100 && pool.getCorePoolSize() == 1 ) {
		pool.setCorePoolSize( 6 );
		pool.setMaximumPoolSize( 6 );
	}

	// blocking for testing
	logger.info( "eventPostPool terminated: {}", eventPostPool.isTerminated() );
	Future<String> futureResult = eventPostPool.submit( new EventPostRunnable( lifecycleSettings.getEventUrl(),
		formParams, "test", "test" ) );

	// Non Blocking to test event caching/pooling
	// futureResult.get() ;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:23,代码来源:CsapEventClient.java

示例2: getThreadPoolSize

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public int getThreadPoolSize() {
    if (executorService instanceof ThreadPoolExecutor) {
        ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService;
        return pool.getCorePoolSize();
    }

    return 0;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:9,代码来源:OtterController.java

示例3: fireServerAttributeUpdateEvent

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Fire server attribute update event.
 *
 * @param source
 *         the source
 * @param attrs
 *         the config
 */
protected void fireServerAttributeUpdateEvent(JsfUrl source, Map<String, String> attrs) {
    LOGGER.info("Get server attribute update callback event, source: {}, data: {}", source, attrs);
    if (CommonUtils.isNotEmpty(attrs)) { // 需要区分alias
        try {
            int port = Integer.parseInt(attrs.get("port"));
            ThreadPoolExecutor executor = BusinessPool.getBusinessPool(port);
            if (executor != null) {
                if (attrs.containsKey("core")) {
                    int coreNew = Integer.parseInt(attrs.get("core"));
                    if (coreNew != executor.getCorePoolSize()) {
                        LOGGER.info("Core pool size of business pool at port {} change from {} to {}",
                                new Object[]{port, executor.getCorePoolSize(), coreNew});
                        executor.setCorePoolSize(coreNew);
                    }
                }
                if (attrs.containsKey("max")) {
                    int maxNew = Integer.parseInt(attrs.get("max"));
                    if (maxNew != executor.getMaximumPoolSize()) {
                        LOGGER.info("Maximum pool size of business pool at port {} change from {} to {}",
                                new Object[]{port, executor.getMaximumPoolSize(), maxNew});
                        executor.setMaximumPoolSize(maxNew);
                    }
                }
            }
        } catch (Exception e) {
            LOGGER.warn("Fire server attribute update event error!", e);
        }
    }
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:38,代码来源:RegistryCallbackHandler.java

示例4: serviceStart

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
protected void serviceStart() throws Exception {
  client.start();

  ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat(
      this.getClass().getName() + " #%d").setDaemon(true).build();

  // Start with a default core-pool size and change it dynamically.
  int initSize = Math.min(INITIAL_THREAD_POOL_SIZE, maxThreadPoolSize);
  threadPool = new ThreadPoolExecutor(initSize, Integer.MAX_VALUE, 1,
      TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>(), tf);

  eventDispatcherThread = new Thread() {
    @Override
    public void run() {
      ContainerEvent event = null;
      Set<String> allNodes = new HashSet<String>();

      while (!stopped.get() && !Thread.currentThread().isInterrupted()) {
        try {
          event = events.take();
        } catch (InterruptedException e) {
          if (!stopped.get()) {
            LOG.error("Returning, thread interrupted", e);
          }
          return;
        }

        allNodes.add(event.getNodeId().toString());

        int threadPoolSize = threadPool.getCorePoolSize();

        // We can increase the pool size only if haven't reached the maximum
        // limit yet.
        if (threadPoolSize != maxThreadPoolSize) {

          // nodes where containers will run at *this* point of time. This is
          // *not* the cluster size and doesn't need to be.
          int nodeNum = allNodes.size();
          int idealThreadPoolSize = Math.min(maxThreadPoolSize, nodeNum);

          if (threadPoolSize < idealThreadPoolSize) {
            // Bump up the pool size to idealThreadPoolSize +
            // INITIAL_POOL_SIZE, the later is just a buffer so we are not
            // always increasing the pool-size
            int newThreadPoolSize = Math.min(maxThreadPoolSize,
                idealThreadPoolSize + INITIAL_THREAD_POOL_SIZE);
            LOG.info("Set NMClientAsync thread pool size to " +
                newThreadPoolSize + " as the number of nodes to talk to is "
                + nodeNum);
            threadPool.setCorePoolSize(newThreadPoolSize);
          }
        }

        // the events from the queue are handled in parallel with a thread
        // pool
        threadPool.execute(getContainerEventProcessor(event));

        // TODO: Group launching of multiple containers to a single
        // NodeManager into a single connection
      }
    }
  };
  eventDispatcherThread.setName("Container  Event Dispatcher");
  eventDispatcherThread.setDaemon(false);
  eventDispatcherThread.start();

  super.serviceStart();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:70,代码来源:NMClientAsyncImpl.java

示例5: serviceStart

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
protected void serviceStart() throws Exception {

    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat(
        "ContainerLauncher #%d").setDaemon(true).build();

    // Start with a default core-pool size of 10 and change it dynamically.
    launcherPool = new ThreadPoolExecutor(initialPoolSize,
        Integer.MAX_VALUE, 1, TimeUnit.HOURS,
        new LinkedBlockingQueue<Runnable>(),
        tf);
    eventHandlingThread = new Thread() {
      @Override
      public void run() {
        ContainerLauncherEvent event = null;
        Set<String> allNodes = new HashSet<String>();

        while (!stopped.get() && !Thread.currentThread().isInterrupted()) {
          try {
            event = eventQueue.take();
          } catch (InterruptedException e) {
            if (!stopped.get()) {
              LOG.error("Returning, interrupted : " + e);
            }
            return;
          }
          allNodes.add(event.getContainerMgrAddress());

          int poolSize = launcherPool.getCorePoolSize();

          // See if we need up the pool size only if haven't reached the
          // maximum limit yet.
          if (poolSize != limitOnPoolSize) {

            // nodes where containers will run at *this* point of time. This is
            // *not* the cluster size and doesn't need to be.
            int numNodes = allNodes.size();
            int idealPoolSize = Math.min(limitOnPoolSize, numNodes);

            if (poolSize < idealPoolSize) {
              // Bump up the pool size to idealPoolSize+initialPoolSize, the
              // later is just a buffer so we are not always increasing the
              // pool-size
              int newPoolSize = Math.min(limitOnPoolSize, idealPoolSize
                  + initialPoolSize);
              LOG.info("Setting ContainerLauncher pool size to " + newPoolSize
                  + " as number-of-nodes to talk to is " + numNodes);
              launcherPool.setCorePoolSize(newPoolSize);
            }
          }

          // the events from the queue are handled in parallel
          // using a thread pool
          launcherPool.execute(createEventProcessor(event));

          // TODO: Group launching of multiple containers to a single
          // NodeManager into a single connection
        }
      }
    };
    eventHandlingThread.setName("ContainerLauncher Event Handler");
    eventHandlingThread.start();
    super.serviceStart();
  }
 
开发者ID:naver,项目名称:hadoop,代码行数:64,代码来源:ContainerLauncherImpl.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.getCorePoolSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。