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

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

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

ThreadPoolExecutor.prestartCoreThread介绍

[英]Starts a core thread, causing it to idly wait for work. This overrides the default policy of starting core threads only when new tasks are executed. This method will return falseif all core threads have already been started.
[中]启动核心线程,使其空闲等待工作。这将覆盖仅在执行新任务时启动核心线程的默认策略。如果所有核心线程都已启动,此方法将返回False。

代码示例

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

/**
 * Starts the services used by the HttpSessionManager.
 *
 * (Re)creates and configures a pooled executor to handle async routing for incoming packets with a configurable
 * (through property "xmpp.httpbind.worker.threads") amount of threads; also uses an unbounded task queue and
 * configurable ("xmpp.httpbind.worker.timeout") keep-alive.
 *
 * Note: Apart from the processing threads configured in this class, the server also uses a threadpool to perform
 * the network IO (as configured in ({@link HttpBindManager}). BOSH installations expecting heavy loads may want to
 * allocate additional threads to this worker pool to ensure timely delivery of inbound packets
 */
public void start() {
  Log.info( "Starting instance" );
  this.sessionManager = SessionManager.getInstance();
  final int maxClientPoolSize = JiveGlobals.getIntProperty( "xmpp.client.processing.threads", 8 );
  final int maxPoolSize = JiveGlobals.getIntProperty("xmpp.httpbind.worker.threads", maxClientPoolSize );
  final int keepAlive = JiveGlobals.getIntProperty( "xmpp.httpbind.worker.timeout", 60 );
  sendPacketPool = new ThreadPoolExecutor(getCorePoolSize(maxPoolSize), maxPoolSize, keepAlive, TimeUnit.SECONDS,
      new LinkedBlockingQueue<Runnable>(), // unbounded task queue
      new NamedThreadFactory( "httpbind-worker-", true, null, Thread.currentThread().getThreadGroup(), null )
  );
  sendPacketPool.prestartCoreThread();
  // Periodically check for Sessions that need a cleanup.
  inactivityTask = new HttpSessionReaper();
  TaskEngine.getInstance().schedule( inactivityTask, 30 * JiveConstants.SECOND, 30 * JiveConstants.SECOND );
}

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

@Override
protected void doStart() throws Exception
{
  if (_executor.isShutdown())
    throw new IllegalStateException("This thread pool is not restartable");
  for (int i = 0; i < _minThreads; ++i)
    _executor.prestartCoreThread();
  _tryExecutor = new ReservedThreadExecutor(this, _reservedThreads);
  addBean(_tryExecutor);
  super.doStart();
}

代码示例来源:origin: ch.cmbntr/modulizer-bootstrap

private static ThreadPoolExecutor buildNonBlockableExecutor() {
 final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>();
 final ThreadPoolExecutor tpe = new ThreadPoolExecutor(POOL_SIZE, POOL_SIZE, 15L, TimeUnit.SECONDS, workQueue,
   THREAD_FACTORY);
 tpe.allowCoreThreadTimeOut(true);
 tpe.prestartCoreThread();
 return tpe;
}

代码示例来源:origin: SpringForAll/spring-boot-starter-hbase

public Connection getConnection() {
  if (null == this.connection) {
    synchronized (this) {
      if (null == this.connection) {
        try {
          ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(200, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
          // init pool
          poolExecutor.prestartCoreThread();
          this.connection = ConnectionFactory.createConnection(configuration, poolExecutor);
        } catch (IOException e) {
          LOGGER.error("hbase connection资源池创建失败");
        }
      }
    }
  }
  return this.connection;
}

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

private void startEstimatePool() {
 int minPoolSize = conf.getInt(ESTIMATE_POOL_MIN_THREADS,
  DEFAULT_ESTIMATE_POOL_MIN_THREADS);
 int maxPoolSize = conf.getInt(ESTIMATE_POOL_MAX_THREADS,
  DEFAULT_ESTIMATE_POOL_MAX_THREADS);
 int keepAlive = conf.getInt(ESTIMATE_POOL_KEEP_ALIVE_MILLIS,
  DEFAULT_ESTIMATE_POOL_KEEP_ALIVE_MILLIS);
 final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
 final AtomicInteger thId = new AtomicInteger();
 // We are creating our own thread factory, just so that we can override thread name for easy debugging
 ThreadFactory threadFactory = new ThreadFactory() {
  @Override
  public Thread newThread(Runnable r) {
   Thread th = defaultFactory.newThread(r);
   th.setName("estimate-" + thId.incrementAndGet());
   return th;
  }
 };
 log.debug("starting estimate pool");
 ThreadPoolExecutor estimatePool = new ThreadPoolExecutor(minPoolSize, maxPoolSize, keepAlive, TimeUnit.MILLISECONDS,
  new SynchronousQueue<Runnable>(), threadFactory);
 estimatePool.allowCoreThreadTimeOut(false);
 estimatePool.prestartCoreThread();
 this.estimatePool = estimatePool;
}

代码示例来源:origin: org.mariadb.jdbc/mariadb-java-client

/**
 * Add new connection if needed. Only one thread create new connection, so new connection request
 * will wait to newly created connection or for a released connection.
 */
private void addConnectionRequest() {
 if (totalConnection.get() < options.maxPoolSize && poolState.get() == POOL_STATE_OK) {
  //ensure to have one worker if was timeout
  connectionAppender.prestartCoreThread();
  connectionAppenderQueue.offer(() -> {
   if ((totalConnection.get() < options.minPoolSize || pendingRequestNumber.get() > 0)
     && totalConnection.get() < options.maxPoolSize) {
    try {
     addConnection();
    } catch (SQLException sqle) {
     //eat
    }
   }
  });
 }
}

代码示例来源:origin: MariaDB/mariadb-connector-j

/**
 * Add new connection if needed. Only one thread create new connection, so new connection request
 * will wait to newly created connection or for a released connection.
 */
private void addConnectionRequest() {
 if (totalConnection.get() < options.maxPoolSize && poolState.get() == POOL_STATE_OK) {
  //ensure to have one worker if was timeout
  connectionAppender.prestartCoreThread();
  connectionAppenderQueue.offer(() -> {
   if ((totalConnection.get() < options.minPoolSize || pendingRequestNumber.get() > 0)
     && totalConnection.get() < options.maxPoolSize) {
    try {
     addConnection();
    } catch (SQLException sqle) {
     //eat
    }
   }
  });
 }
}

代码示例来源:origin: tywo45/t-io

/**
   * 
   * @return
   * @author tanyaowu
   */
  public static ThreadPoolExecutor getGroupExecutor() {
    if (groupExecutor != null) {
      return groupExecutor;
    }

    synchronized (Threads.class) {
      if (groupExecutor != null) {
        return groupExecutor;
      }

      LinkedBlockingQueue<Runnable> groupQueue = new LinkedBlockingQueue<>();
      //			ArrayBlockingQueue<Runnable> groupQueue = new ArrayBlockingQueue<>(QUEUE_CAPACITY);
      String groupThreadName = "tio-group";
      DefaultThreadFactory defaultThreadFactory = DefaultThreadFactory.getInstance(groupThreadName, Thread.MAX_PRIORITY);

      groupExecutor = new ThreadPoolExecutor(MAX_POOL_SIZE_FOR_GROUP, MAX_POOL_SIZE_FOR_GROUP, KEEP_ALIVE_TIME, TimeUnit.SECONDS, groupQueue, defaultThreadFactory);
      //			groupExecutor = new ThreadPoolExecutor(AVAILABLE_PROCESSORS * 2, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), defaultThreadFactory);

      groupExecutor.prestartCoreThread();
//            groupExecutor.prestartAllCoreThreads();
      return groupExecutor;
    }
  }

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

private void startLauncherPool() {
 int minPoolSize = conf.getInt(LAUNCHER_POOL_MIN_THREADS,
  DEFAULT_LAUNCHER_POOL_MIN_THREADS);
 int maxPoolSize = conf.getInt(LAUNCHER_POOL_MAX_THREADS,
  DEFAULT_LAUNCHER_POOL_MAX_THREADS);
 int keepAlive = conf.getInt(LAUNCHER_POOL_KEEP_ALIVE_MILLIS,
  DEFAULT_LAUNCHER_POOL_KEEP_ALIVE_MILLIS);
 final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
 final AtomicInteger thId = new AtomicInteger();
 // We are creating our own thread factory, just so that we can override thread name for easy debugging
 ThreadFactory threadFactory = new ThreadFactory() {
  @Override
  public Thread newThread(Runnable r) {
   Thread th = defaultFactory.newThread(r);
   th.setName("launcher-" + thId.incrementAndGet());
   return th;
  }
 };
 log.debug("starting query launcher pool");
 ThreadPoolExecutor launcherPool = new ThreadPoolExecutor(minPoolSize, maxPoolSize, keepAlive, TimeUnit.MILLISECONDS,
  new SynchronousQueue<Runnable>(), threadFactory);
 launcherPool.allowCoreThreadTimeOut(false);
 launcherPool.prestartCoreThread();
 this.queryLauncherPool = launcherPool;
}
private void startQueryCancellationPool() {

代码示例来源:origin: gearman/java-service

public GearmanImpl(int coreThreads) throws IOException {
  if(coreThreads<=0)
    throw new IllegalArgumentException("GearmanImpl needs 1 or more threads");
  
  final ThreadFactory threadFactory = new GearmanThreadFactory();
  
  final ThreadPoolExecutor pool = new ThreadPoolExecutor(coreThreads, Integer.MAX_VALUE, GearmanUtils.getThreadTimeout(), TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), threadFactory);
  pool.allowCoreThreadTimeOut(false);
  pool.prestartCoreThread();
  
  this.scheduler = new Scheduler(pool, threadFactory); 
  this.connectionManager = new GearmanConnectionManager(scheduler);
}

代码示例来源:origin: jenkinsci/winstone

@Override
protected void doStart() throws Exception
{
  if (_executor.isShutdown())
    throw new IllegalStateException("This thread pool is not restartable");
  for (int i = 0; i < _minThreads; ++i)
    _executor.prestartCoreThread();
  _tryExecutor = new ReservedThreadExecutor(this, _reservedThreads);
  addBean(_tryExecutor);
  super.doStart();
}

代码示例来源:origin: net.sf.extcos/extcos

private ThreadPoolExecutor getExecutor() {
  if (executor == null) {
    executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
    executor.setCorePoolSize(5 > registered.get() ? registered.get() : 5);
    executor.setMaximumPoolSize(10);
    executor.setThreadFactory(new ThreadFactory() {
      private ThreadGroup threadGroup;
      @Override
      public Thread newThread(final Runnable runnable) {
        Thread thread = new Thread(getThreadGroup(), runnable, append("eXtcos managed thread ", getInvoked()));
        thread.setDaemon(true);
        return thread;
      }
      private ThreadGroup getThreadGroup() {
        if (threadGroup == null) {
          threadGroup = new ThreadGroup("eXtcos Thread Group");
          threadGroup.setDaemon(true);
        }
        return threadGroup;
      }
    });
    executor.prestartCoreThread();
  }
  return executor;
}

代码示例来源:origin: dCache/dcache

new LinkedBlockingQueue<>(),
                killerThreadFactory);
emergencyKillerExecutor.prestartCoreThread();
_emergencyKillerExecutor = MoreExecutors.listeningDecorator(emergencyKillerExecutor);

代码示例来源:origin: com.sonyericsson.hudson.plugins.gerrit/gerrit-events

executor.allowCoreThreadTimeOut(true);
  executor.prestartCoreThread();
  logger.info("SendQueue started! Current pool size: {}", executor.getPoolSize());
} else {

代码示例来源:origin: org.hudsonci.plugins/gerrit-events

executor.allowCoreThreadTimeOut(true);
  executor.prestartCoreThread();
  logger.info("SendQueue started! Current pool size: {}", executor.getPoolSize());
} else {

代码示例来源:origin: jenkinsci/build-failure-analyzer-plugin

/**
 * Starts the executor if it hasn't started yet, or updates the thread-pool size if it is started.
 *
 */
protected void startQueue() {
  if (executor == null) {
    logger.debug("Starting the sending thread pool.");
    executor = new ThreadPoolExecutor(
        PluginImpl.getInstance().getSodVariables().getMinimumSodWorkerThreads(),
        PluginImpl.getInstance().getSodVariables().getMinimumSodWorkerThreads(),
        PluginImpl.getInstance().getSodVariables().getSodThreadKeepAliveTime(), TimeUnit.MINUTES,
        new LinkedBlockingQueue<Runnable>());
    executor.allowCoreThreadTimeOut(true);
    executor.prestartCoreThread();
    logger.info("SendQueue started! Current pool size: {}", executor.getPoolSize());
  }
  executor.setMaximumPoolSize(PluginImpl.getInstance().getSodVariables().getMaximumSodWorkerThreads());
  executor.setCorePoolSize(PluginImpl.getInstance().getSodVariables().getSodCorePoolNumberOfThreads());
  logger.debug("SendQueue running. Current pool size: {}. Current Queue size: {}",
      executor.getPoolSize(), getQueueSize());
  logger.debug("Nr of active pool-threads: {}", executor.getActiveCount());
}

代码示例来源:origin: org.igniterealtime.openfire/xmppserver

/**
 * Starts the services used by the HttpSessionManager.
 *
 * (Re)creates and configures a pooled executor to handle async routing for incoming packets with a configurable
 * (through property "xmpp.httpbind.worker.threads") amount of threads; also uses an unbounded task queue and
 * configurable ("xmpp.httpbind.worker.timeout") keep-alive.
 *
 * Note: Apart from the processing threads configured in this class, the server also uses a threadpool to perform
 * the network IO (as configured in ({@link HttpBindManager}). BOSH installations expecting heavy loads may want to
 * allocate additional threads to this worker pool to ensure timely delivery of inbound packets
 */
public void start() {
  Log.info( "Starting instance" );
  this.sessionManager = SessionManager.getInstance();
  final int maxClientPoolSize = JiveGlobals.getIntProperty( "xmpp.client.processing.threads", 8 );
  final int maxPoolSize = JiveGlobals.getIntProperty("xmpp.httpbind.worker.threads", maxClientPoolSize );
  final int keepAlive = JiveGlobals.getIntProperty( "xmpp.httpbind.worker.timeout", 60 );
  sendPacketPool = new ThreadPoolExecutor(getCorePoolSize(maxPoolSize), maxPoolSize, keepAlive, TimeUnit.SECONDS,
      new LinkedBlockingQueue<Runnable>(), // unbounded task queue
      new NamedThreadFactory( "httpbind-worker-", true, null, Thread.currentThread().getThreadGroup(), null )
  );
  sendPacketPool.prestartCoreThread();
  // Periodically check for Sessions that need a cleanup.
  inactivityTask = new HttpSessionReaper();
  TaskEngine.getInstance().schedule( inactivityTask, 30 * JiveConstants.SECOND, 30 * JiveConstants.SECOND );
}

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

@Test
public void idleThreadPoolExecutorSynchronousQueueTest() {
 ThreadPoolExecutor tpe = new ThreadPoolExecutor(1, 1, 100, TimeUnit.MILLISECONDS, 
                         new SynchronousQueue<>());
 profilingExecutor(tpe);
 tpe.prestartCoreThread();
 profiler.start();
 blockForProfilerSample();
 verifyDumpContains("ThreadPoolExecutor SynchronousQueue idle thread");
}

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

@Test
public void idleThreadPoolExecutorArrayBlockingQueueTest() {
 ThreadPoolExecutor tpe = new ThreadPoolExecutor(1, 1, 100, TimeUnit.MILLISECONDS, 
                         new ArrayBlockingQueue<>(1));
 profilingExecutor(tpe);
 tpe.prestartCoreThread();
 profiler.start();
 blockForProfilerSample();
 verifyDumpContains("ThreadPoolExecutor ArrayBlockingQueue idle thread");
}

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

@Test
public void idleThreadPoolExecutorLinkedBlockingQueueTest() {
 ThreadPoolExecutor tpe = new ThreadPoolExecutor(1, 1, 100, TimeUnit.MILLISECONDS, 
                         new LinkedBlockingQueue<>());
 profilingExecutor(tpe);
 tpe.prestartCoreThread();
 profiler.start();
 blockForProfilerSample();
 verifyDumpContains("ThreadPoolExecutor LinkedBlockingQueue idle thread");
}

相关文章

ThreadPoolExecutor类方法