Package com.google.apphosting.runtime
Class ThreadGroupPool
- java.lang.Object
-
- com.google.apphosting.runtime.ThreadGroupPool
-
public class ThreadGroupPool extends Object
ThreadGroupPoolis a very simple thread pool where each pooled thread is in its ownThreadGroup. 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 tostart(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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classThreadGroupPool.BuilderBuilder for ThreadGroupPool.
-
Constructor Summary
Constructors Constructor Description ThreadGroupPool(ThreadGroup parentThreadGroup, String threadGroupNamePrefix, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, boolean ignoreDaemonThreads)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ThreadGroupPool.Builderbuilder()static CountDownLatchresetCurrentThread()If the current thread is main thread started in response to a call tostart(java.lang.String, java.lang.Runnable), this method will arrange for it to expect to be "restarted." SeeThreadGroupPool.RestartableThreadfor more information.voidstart(String threadName, Runnable runnable)Executerunnablein a thread namedthreadName.intwaitingThreadCount()
-
-
-
Constructor Detail
-
ThreadGroupPool
public ThreadGroupPool(ThreadGroup parentThreadGroup, String threadGroupNamePrefix, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, boolean ignoreDaemonThreads)
-
-
Method Detail
-
builder
public static ThreadGroupPool.Builder builder()
-
start
public void start(String threadName, Runnable runnable) throws InterruptedException
Executerunnablein a thread namedthreadName. 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.runnablecan spawn other threads in the pooledThreadGroup, 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 executingRunnable.run()onrunnablethrows 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 tostart(java.lang.String, java.lang.Runnable), this method will arrange for it to expect to be "restarted." SeeThreadGroupPool.RestartableThreadfor more information.- Throws:
IllegalStateException- If the current thread is not a main thread.InterruptedException
-
-