Class ThreadingOptions


  • public class ThreadingOptions
    extends Object
    A set of hooks that allow clients to customize the driver's internal executors.

    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 Detail

      • ThreadingOptions

        public ThreadingOptions()
    • Method Detail

      • createThreadFactory

        public ThreadFactory createThreadFactory​(String clusterName,
                                                 String executorName)
        Builds a thread factory for the threads created by a given executor.

        This is used by the default implementations in this class, and also internally to create the Netty I/O pool.

        Parameters:
        clusterName - the name of the cluster, as specified by Cluster.Builder.withClusterName(String).
        executorName - a name that identifies the executor.
        Returns:
        the thread factory.
      • createExecutor

        public ExecutorService createExecutor​(String clusterName)
        Builds the main internal executor, used for tasks such as scheduling speculative executions, triggering registered SchemaChangeListeners, reacting to node state changes, and metadata updates.

        The default implementation sets the pool size to the number of available cores.

        Parameters:
        clusterName - the name of the cluster, as specified by Cluster.Builder.withClusterName(String).
        Returns:
        the executor.
      • createBlockingExecutor

        public ExecutorService createBlockingExecutor​(String clusterName)
        Builds the executor used to block on new connections before they are added to a pool.

        The default implementation uses 2 threads.

        Parameters:
        clusterName - the name of the cluster, as specified by Cluster.Builder.withClusterName(String).
        Returns:
        the executor.
      • createReconnectionExecutor

        public ScheduledExecutorService createReconnectionExecutor​(String clusterName)
        Builds the executor when reconnection attempts will be scheduled.

        The default implementation uses 2 threads.

        Parameters:
        clusterName - the name of the cluster, as specified by Cluster.Builder.withClusterName(String).
        Returns:
        the executor.
      • createScheduledTasksExecutor

        public ScheduledExecutorService createScheduledTasksExecutor​(String clusterName)
        Builds the executor to handle host state notifications from Cassandra.

        This executor must have exactly one thread so that notifications are processed in order.

        Parameters:
        clusterName - the name of the cluster, as specified by Cluster.Builder.withClusterName(String).
        Returns:
        the executor.
      • createReaperExecutor

        public ScheduledExecutorService createReaperExecutor​(String clusterName)
        Builds the executor for an internal maintenance task used to clean up closed connections.

        A single scheduled task runs on this executor, so there is no reason to use more than one thread.

        Parameters:
        clusterName - the name of the cluster, as specified by Cluster.Builder.withClusterName(String).
        Returns:
        the executor.