CREATE ASYNC EXECUTOR

Syntax

CREATE ASYNC EXECUTOR name ['(' executorArg [, ...] ')'] [IF bool_expr]

executorArg:
      MIN_THREAD_COUNT ':' int_expr
    | MAX_THREAD_COUNT ':' int_expr
    | KEEP_ALIVE_SECS ':' long_expr

Description

Creates a named AsyncExecutor.

  • An AsyncExecutor provides a thread pool for asynchronous query execution.
  • An AsyncExecutor is assigned using HConnection.setAsyncExecutorName(). Multiple connections can share a common AsyncExecutor name.
  • AsyncExecutor name assignments are reset when HConnection.close() is called. So if an HConnection is taken from an HConnectionPool, the AsyncExecutor name assignments should be made when an HConnection is retrieved from a pool.
  • AsyncExecutors are used in asynchronous queries such that each query is executed by a thread in the AsyncExecutor thread pool.
  • The number of concurrent asynchronous queries executed (across all connections referencing an AsyncExecutor name) is bound by the size of the AsyncExecutor thread pool.
  • An asynchronous query call will not block if all threads in an AsyncExecutor thread pool are busy, but execution will not occur until the thread pool has an available thread. A thread is released back to the AsyncExecutor thread pool on query completion (when the ResultSet iterator is completed).
  • AsyncExecutors are not used by synchronous queries.
  • AsyncExecutors work with and without QueryExecutorPools.

Parameters

  • Each AsyncExecutor has a thread pool specified by these parameters:
    • MIN_THREAD_COUNT - the number of threads to keep in the pool, even if they are idle.
    • MAX_THREAD_COUNT - the maximum number of threads to allow in the pool.
    • KEEP_ALIVE_SECS - when the number of threads is greater than the minimum thread count, KEEP_ALIVE_SECS is the maximum number of seconds that excess idle threads will wait for new tasks before terminating.
  • All the executorArg parameters are optional. If unspecified, the values default to:
    • AsyncExecutorManager.defaultMinThreadCount (1)
    • AsyncExecutorManager.defaultMaxThreadCount (10)
    • AsyncExecutorManager.defaultKeepAliveSecs (Long.MAX_VALUE)

Example

        HConnection conn = HConnectionManager.newConnection();

        // Create AsyncExecutor named asyncExec if it doesn't already exist.
        conn.execute("CREATE ASYNC EXECUTOR asyncExec (MAX_THREAD_COUNT: 10) IF NOT asyncExecutorExists('asyncExec')");

        // Or, using the API
        if (!AsyncExecutorManager.asyncExecutorExists("asyncExec"))
            AsyncExecutorManager.newAsyncExecutor("asyncExec", 5, 10, Long.MAX_VALUE);

        // Then assign the connection an AsyncExecutor name to use for queries
        conn.setAsyncExecutorName("asyncExec");

        // Now use connection in a query.