ThreadManager

public abstract classThreadManager extends Object

An interface that controls the thread pools and thread factories used by the Admin SDK. Each instance ofFirebaseApp uses an implementation of this interface to create and manage threads.

Multiple app instances may use the sameThreadManager instance. Methods in this interface may get invoked multiple times by the same app, during its lifetime. Apps may also invoke methods of this interface concurrently and so implementations should provide any synchronization necessary.

Public Constructor Summary

Protected Method Summary

abstract ExecutorService
getExecutor(FirebaseApp app)
Returns the main thread pool for an app.
abstract ThreadFactory
getThreadFactory()
Returns theThreadFactory to be used for creating long-lived threads.
abstract void
releaseExecutor(FirebaseApp app, ExecutorService executor)
Cleans up the thread pool associated with an app.

Inherited Method Summary

From class java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
final Class<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()

Public Constructors

publicThreadManager()

Protected Methods

protected abstract ExecutorServicegetExecutor(FirebaseApp app)

Returns the main thread pool for an app. Implementations may return the same instance ofExecutorService for multiple apps. The returned thread pool is used for short-lived tasks by all components of an app.

For long-lived tasks (such as the ones started by the Realtime Database client), the SDK creates dedicated executors using theThreadFactory returned by thegetThreadFactory() method.

Parameters
appAFirebaseApp instance.
Returns
  • A non-nullExecutorService instance.

protected abstract ThreadFactorygetThreadFactory()

Returns theThreadFactory to be used for creating long-lived threads. This is used mainly to create the long-lived worker threads for the Realtime Database client, and other scheduled (periodic) tasks started by the SDK. The SDK guarantees clean termination of all threads started via thisThreadFactory, when the user callsdelete().

If long-lived threads cannot be supported in the current runtime, this method may throw aRuntimeException.

Returns
  • A non-nullThreadFactory.

protected abstract voidreleaseExecutor(FirebaseApp app, ExecutorService executor)

Cleans up the thread pool associated with an app. This method is invoked when an app is deleted. This is guaranteed to be called with theExecutorService previously returned bygetExecutor(FirebaseApp) for the corresponding app.

Parameters
appAFirebaseApp instance.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2021-04-28 UTC.