Exemplo n.º 1
0
 @Bean
 public ApiController apiController(ThreadPoolExecutor executor) {
   executor.setCorePoolSize(4);
   executor.setMaximumPoolSize(4);
   ApiController controller = new ApiController(executor);
   return controller;
 }
Exemplo n.º 2
0
 private void update() {
   // 更新ThreadPoolExecutor
   int eventThreadPoolSize = this.getSettings().getInteger("hasor.eventThreadPoolSize", 20);
   ThreadPoolExecutor threadPool = (ThreadPoolExecutor) executorService;
   threadPool.setCorePoolSize(eventThreadPoolSize);
   threadPool.setMaximumPoolSize(eventThreadPoolSize);
 }
Exemplo n.º 3
0
 // 调整一下线程池
 public void adjustPoolSize(int newPoolSize) {
   if (newPoolSize != poolSize) {
     poolSize = newPoolSize;
     if (executor instanceof ThreadPoolExecutor) {
       ThreadPoolExecutor pool = (ThreadPoolExecutor) executor;
       pool.setCorePoolSize(newPoolSize);
       pool.setMaximumPoolSize(newPoolSize);
     }
   }
 }
Exemplo n.º 4
0
  /**
   * Sets the maximum number of worker threads in the thread pool. <br>
   * This equals the maximum number of concurrent requests this AgiServer can serve. <br>
   * The default maximum pool size is 100.
   *
   * @param maximumPoolSize the maximum size of the worker thread pool.
   * @throws IllegalArgumentException if maximumPoolSize is less than current pool size or less than
   *     or equal to 0.
   * @see java.util.concurrent.ThreadPoolExecutor#setMaximumPoolSize(int)
   */
  public synchronized void setMaximumPoolSize(int maximumPoolSize) {
    if (maximumPoolSize <= 0) {
      throw new IllegalArgumentException(
          "New maximumPoolSize (" + maximumPoolSize + ") is must be positive");
    }

    if (maximumPoolSize < poolSize) {
      throw new IllegalArgumentException(
          "New maximumPoolSize ("
              + maximumPoolSize
              + ") is less than current pool size ("
              + poolSize
              + ")");
    }

    if (pool != null) {
      pool.setMaximumPoolSize(maximumPoolSize);
    }
    this.maximumPoolSize = maximumPoolSize;
  }
Exemplo n.º 5
0
  /** Submit exec into pool and throw exceptions */
  public void execute() {
    String p = project.getProperty("number.of.threads");
    if (p != null) {
      ((ThreadPoolExecutor) threadPool).setCorePoolSize(Integer.parseInt(p));
      ((ThreadPoolExecutor) threadPool).setMaximumPoolSize(Integer.parseInt(p));
    }
    TaskRunnable tr = new TaskRunnable();
    threadPool.submit(tr);
    try {
      synchronized (semaphore) {
        while (!tr.isFinished()) semaphore.wait();
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    Throwable t = tr.getException();
    if (t != null) {
      if (t instanceof BuildException) throw (BuildException) t;
      else t.printStackTrace();
    }
  }
 public void setMaxThreads(int maxThreads) {
   this.maxThreads = maxThreads;
   if (executor != null) {
     executor.setMaximumPoolSize(maxThreads);
   }
 }
 public void setMaxThreadCount(int maxThreadCount) {
   executor.setCorePoolSize(maxThreadCount);
   executor.setMaximumPoolSize(maxThreadCount);
 }
Exemplo n.º 8
0
 public void setMaxThreads(int size) {
   pool.setMaximumPoolSize(size);
 }
Exemplo n.º 9
0
 /**
  * Sets the core number of threads in the internal {@link ThreadPoolExecutor}.
  *
  * @param size - the new core size
  * @see ThreadPoolExecutor#setCorePoolSize(int)
  */
 public static void setCorePoolSize(int size) {
   threadPool.setCorePoolSize(size);
   threadPool.setMaximumPoolSize(size);
 }