Esempio n. 1
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 testMustNotBeAbleToShutdownGlobalPool() {
   ExecutorService service = AppExecutorUtil.getAppExecutorService();
   try {
     service.shutdown();
     fail();
   } catch (Exception ignored) {
   }
   try {
     service.shutdownNow();
     fail();
   } catch (Exception ignored) {
   }
   try {
     ((ThreadPoolExecutor) service).setThreadFactory(Thread::new);
     fail();
   } catch (Exception ignored) {
   }
   try {
     ((ThreadPoolExecutor) service).setCorePoolSize(0);
     fail();
   } catch (Exception ignored) {
   }
 }
Esempio n. 3
0
 public void setMinThreads(int size) {
   pool.setCorePoolSize(size);
 }