Class ThreadGroupPool

java.lang.Object
com.google.apphosting.runtime.ThreadGroupPool

public class ThreadGroupPool extends Object
ThreadGroupPool is a very simple thread pool where each pooled thread is in its own ThreadGroup. Unfortunately threads cannot be moved around between thread groups, so we just pool (ThreadGroup, Thread) pairs. If additional threads are started in a thread group, they are expected to have exited before the runnable provided to start(java.lang.String, java.lang.Runnable) completes. If this is not the case, the thread will be dropped from the thread pool and detailed diagnostics will be written to the log.

Unlike thread names, thread group names are immutable so thread groups will be named with a specified prefix with a counter appended. The name of the main thread for each thread pool is determined when start(java.lang.String, java.lang.Runnable) is called.

  • Constructor Details

  • Method Details

    • builder

      public static ThreadGroupPool.Builder builder()
    • start

      public void start(String threadName, Runnable runnable) throws InterruptedException
      Execute runnable in a thread named threadName. This may be a newly created thread or it may be a thread that was was already used to run one or more previous invocations.

      runnable can spawn other threads in the pooled ThreadGroup, but they must all exit before the runnable completes. Failure of the extra threads to complete will result in a severe log message and the dropping of this thread from the pool.

      This method will block until the thread begins executing runnable. If executing Runnable.run() on runnable throws an exception, the thread will not be returned to the thread pool.

      Throws:
      InterruptedException
    • waitingThreadCount

      public int waitingThreadCount()
    • resetCurrentThread

      public static CountDownLatch resetCurrentThread() throws InterruptedException
      If the current thread is main thread started in response to a call to start(java.lang.String, java.lang.Runnable), this method will arrange for it to expect to be "restarted." See ThreadGroupPool.RestartableThread for more information.
      Throws:
      IllegalStateException - If the current thread is not a main thread.
      InterruptedException