public class ThreadingOptions extends Object
The methods in this class are invoked when the cluster initializes. To customize the behavior, extend the class and override the appropriate methods.
This is mainly intended to allow customization and instrumentation of driver threads. Each
method must return a newly-allocated executor; don't use a shared executor, as this could
introduce unintended consequences like deadlocks (we're working to simplify the driver's
architecture and reduce the number of executors in a future release). The default implementations
use unbounded queues, which is appropriate when the driver is properly configured; the only
reason you would want to use bounded queues is to limit memory consumption in case of a bug or
bad configuration. In that case, make sure to use a RejectedExecutionHandler
that throws,
such as ThreadPoolExecutor.AbortPolicy
; a blocking handler could
introduce deadlocks.
Netty uses a separate pool for I/O operations, that can be configured via NettyOptions
.
Constructor and Description |
---|
ThreadingOptions() |
Modifier and Type | Method and Description |
---|---|
ExecutorService |
createBlockingExecutor(String clusterName)
Builds the executor used to block on new connections before they are added to a pool.
|
ExecutorService |
createExecutor(String clusterName)
Builds the main internal executor, used for tasks such as scheduling speculative executions,
triggering registered
SchemaChangeListener s, reacting to node state changes, and
metadata updates. |
ScheduledExecutorService |
createReaperExecutor(String clusterName)
Builds the executor for an internal maintenance task used to clean up closed connections.
|
ScheduledExecutorService |
createReconnectionExecutor(String clusterName)
Builds the executor when reconnection attempts will be scheduled.
|
ScheduledExecutorService |
createScheduledTasksExecutor(String clusterName)
Builds the executor to handle host state notifications from Cassandra.
|
ThreadFactory |
createThreadFactory(String clusterName,
String executorName)
Builds a thread factory for the threads created by a given executor.
|
public ThreadFactory createThreadFactory(String clusterName, String executorName)
This is used by the default implementations in this class, and also internally to create the Netty I/O pool.
clusterName
- the name of the cluster, as specified by Cluster.Builder.withClusterName(String)
.executorName
- a name that identifies the executor.public ExecutorService createExecutor(String clusterName)
SchemaChangeListener
s, reacting to node state changes, and
metadata updates.
The default implementation sets the pool size to the number of available cores.
clusterName
- the name of the cluster, as specified by Cluster.Builder.withClusterName(String)
.public ExecutorService createBlockingExecutor(String clusterName)
The default implementation uses 2 threads.
clusterName
- the name of the cluster, as specified by Cluster.Builder.withClusterName(String)
.public ScheduledExecutorService createReconnectionExecutor(String clusterName)
The default implementation uses 2 threads.
clusterName
- the name of the cluster, as specified by Cluster.Builder.withClusterName(String)
.public ScheduledExecutorService createScheduledTasksExecutor(String clusterName)
This executor must have exactly one thread so that notifications are processed in order.
clusterName
- the name of the cluster, as specified by Cluster.Builder.withClusterName(String)
.public ScheduledExecutorService createReaperExecutor(String clusterName)
A single scheduled task runs on this executor, so there is no reason to use more than one thread.
clusterName
- the name of the cluster, as specified by Cluster.Builder.withClusterName(String)
.Copyright © 2012–2024. All rights reserved.