Package com.google.apphosting.runtime
Class ThreadGroupPool
java.lang.Object
com.google.apphosting.runtime.ThreadGroupPool
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder for ThreadGroupPool. -
Constructor Summary
ConstructorsConstructorDescriptionThreadGroupPool
(ThreadGroup parentThreadGroup, String threadGroupNamePrefix, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, boolean ignoreDaemonThreads) -
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadGroupPool.Builder
builder()
static CountDownLatch
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.RestartableThread
for more information.void
Executerunnable
in a thread namedthreadName
.int
-
Constructor Details
-
ThreadGroupPool
public ThreadGroupPool(ThreadGroup parentThreadGroup, String threadGroupNamePrefix, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, boolean ignoreDaemonThreads)
-
-
Method Details
-
builder
-
start
Executerunnable
in 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.runnable
can 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()
onrunnable
throws an exception, the thread will not be returned to the thread pool.- Throws:
InterruptedException
-
waitingThreadCount
public int waitingThreadCount() -
resetCurrentThread
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.RestartableThread
for more information.- Throws:
IllegalStateException
- If the current thread is not a main thread.InterruptedException
-