OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Connector/J

V2.4.14
  • What is OceanBase Connector J?
    • Overview of OceanBase Connector/J
    • Compatibility requirements
    • Limitations
  • Install Driver
    • Install and load OceanBase Connector/J
  • Instructions
    • Quick start
      • Import packages
      • Establish a database connection
      • Create a Statement object
      • Run queries and retrieve ResultSet objects
      • Process ResultSet objects
      • Close ResultSet and Statement objects
      • Manage tables and data
      • Commit changes
      • Close a database connection
      • Examples
    • Data sources and URL
      • Data source overview
      • Database URL
    • Java data streams
      • Overview of Java data streams
      • LONG and LONG RAW data types
      • Use LOBs
        • Overview of LOB data types
        • LOB data interface
        • LOB locator interface
      • CHAR, VARCHAR, and RAW data types
    • Statement caching
      • Overview of statement caching
      • Use statement caching
      • Reuse statement objects
    • Call a stored procedure
    • Handle SQL exceptions
    • Result set
      • Overview of result sets
      • Limitations
      • FetchSize
      • refreshRow
      • useCursorFetch
    • Batch processing
    • Failover and Load-Balancing
      • Failover and load balancing modes
      • LoadBalance strategies
      • Load balancing strategy configuration methods
    • Rich client
    • Logging
    • Network overheads
    • Show Trace
    • Security features
    • Troubleshooting
  • Reference
    • Features specific to the Oracle mode
      • Binary Protocol (Prepared Statements)
        • COM_STMT_PREPARE_EXECUTE
        • COM_STMT_SEND_PIECE_DATA
      • Call PL stored procedures
      • Scrollability of a result set
      • Use ARRAY and STRUCT classes
      • Distributed transactions
        • Overview
        • XA components
        • Distributed transaction examples
      • Obtain remarks
      • Data types supported in Oracle mode
      • Error messages in Oracle mode
    • Supported SQL and PL data types
    • Common APIs
      • Overview
      • java.sql.Connection
      • java.sql.CallableStatement
      • java.sql.DatabaseMetaData
      • java.sql.Driver
      • java.sql.PreparedStatement
      • java.sql.ParameterMetaData
      • java.sql.ResultSet
      • java.sql.ResultSetMetaData
      • java.sql.Statement
      • javax.sql.ConnectionPoolDataSource
      • javax.naming.Context
      • javax.sql.PooledConnection
      • com.oceanbase.jdbc.ObPrepareStatement
  • Release Notes
    • V2.4
      • OceanBase Connector/J V2.4.14
      • OceanBase Connector/J V2.4.13
      • OceanBase Connector/J V2.4.12
      • OceanBase Connector/J V2.4.11
      • OceanBase Connector/J V2.4.8
      • OceanBase Connector/J V2.4.5
      • OceanBase Connector/J V2.4.4
      • OceanBase Connector/J V2.4.3
      • OceanBase Connector/J V2.4.2
      • OceanBase Connector/J V2.4.1
      • OceanBase Connector/J V2.4.0
    • V2.2
      • OceanBase Connector/J V2.2.11
      • OceanBase Connector/J V2.2.10
      • OceanBase Connector/J V2.2.7
      • OceanBase Connector/J V2.2.6
      • OceanBase Connector/J V2.2.3
      • OceanBase Connector/J V2.2.0

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Connector/J
  3. V2.4.14

LoadBalance strategies

Last Updated:2026-09-04 08:24:26

Load balancing strategies
Load balancing group selection strategy
Blocklist strategies
Examples of blocklist strategies
Related parameters

The LoadBalance mode of OceanBase Connector/J is used for the creation of each Connection object. Each time a Connection object is created, OceanBase Connector/J selects a host from the host list by using the load balancing strategy to establish the connection. LoadBalance based on a configuration file can monitor the corresponding configuration file directory and detect changes after the configuration file is updated. The load balancing strategy, host list, and other information can be updated without modifying the URL each time getConnection is executed.

Load balancing strategies

You can implement three load balancing strategies of OceanBase Connector/J by configuring the OBLB_STRATEGY and LOAD_BALANCE_STRATEGY parameters in the extended configuration information and the loadBalanceStrategy parameter in the URL. The following table describes the strategies.

Algorithm
Feature
Remarks
RANDOM Random load balancing Specifies to use the random algorithm, which is the default load balancing algorithm.
SERVERAFFINITY Weighted load balancing Specifies to use the weighted random algorithm.
ROTATION Rotation load balancing Specifies to use the rotation load balancing algorithm.

Load balancing group selection strategy

OceanBase Connector/J supports only one strategy for load balancing between multiple groups of hosts, which corresponds to the OBLB_GROUP_STRATEGY parameter in the extended configuration information. The following table describes the strategy.

Algorithm
Feature
Remarks
ROTATION Rotation load balancing Specifies to use the rotation load balancing algorithm, which is the default load balancing algorithm.

Blocklist strategies

OceanBase Connector/J allows you to specify strategies for removing and adding blocklist entries with two sub-parameters of OBLB_BLACKLIST. Use the REMOVE_STRATEGY sub-parameter to configure removal strategies, and the APPEND_STRATEGY sub-parameter to configure addition strategies.

OceanBase Connector/J supports two blocklist entry addition strategies, which correspond to the APPEND_STRATEGY sub-parameter. The following table describes the strategies.

Algorithm
Feature
Remarks
NORMAL Normal strategy The default strategy, which specifies to add a host to the blocklist when a network exception occurs during the connection of the host.
RETRYDURATION Retry within a specified period Specifies to add a host to the blocklist after the number of connection retries within a specified period reaches the specified value. This strategy can be configured after you set the RETRYTIMES and DURATION parameters. The unit of DURATION is milliseconds. For example, (RETRYTIMES=3) (DURATION=100) specifies to add the host to the blocklist after three connection retries fail within 100 ms.

OceanBase Connector/J supports only one blocklist entry removal strategy, which corresponds to the REMOVE_STRATEGY sub-parameter. The following table describes the strategies.

Algorithm
Feature
Remarks
TIMEOUT Timeout strategy The default strategy, which specifies to remove a host from the blocklist after the specified timeout period, in milliseconds.

Examples of blocklist strategies

String url = "jdbc:oceanbase:loadbalance://@(NET_SERVICE_NAME=(DESCRIPTION=
  (OBLB=ON)                                                    
  (OBLB_RETRY_ALL_DOWNS=120)
  (OBLB_GROUP_STRATEGY=ROTATION)                               
  (OBLB_BLACKLIST=
      (
        REMOVE_STRATEGY=(
          (NAME=TIMEOUT)
          (TIMEOUT=100)
        )
      )                          
      (
        APPEND_STRATEGY =(
          (NAME=RETRYDURATION)
          (RETRYTIMES=3)
          (DURATION=100)
        )
      )
  )
  (ADDRESS_LIST=
     (OBLB_STRATEGY=SERVERAFFINITY)                          
     (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=port1)(WEIGHT=1))      
     (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=port2)(WEIGHT=10))
  )    
  (ADDRESS_LIST=
     (OBLB_STRATEGY=RANDOM)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
  )
  (ADDRESS_LIST=
     (OBLB_STRATEGY=ROTATION)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
   )
   (CONNECT_DATA=(SERVICE_NAME=OBDATABASE))
))/OBDATABASE?rewriteBatchedStatements=true&allowSendParamTypes=true&prepStmtCacheSize=1000";
Connection = DriverManager.getConnection(url);

Related parameters

Parameter
Description
Default value
Remarks
DESCRIPTION The description for the connection. DESCRIPTION=(). The description of the connection is contained in the parentheses "()". N/A
OBLB Specifies whether to enable load balancing. You can specify this parameter in DESCRIPTION or ADDRESS_LIST. OFF OceanBase Connector/J ignores this parameter because LoadBalance is enabled in the extended configuration information. Also, this parameter does not take effect if it is specified in ADDRESS_LIST. You must configure this parameter later.
LOAD_BALANCE Specifies whether to enable load balancing. You can specify this parameter in DESCRIPTION or ADDRESS_LIST. OFF This parameter is equivalent to OBLB.
OBLB_RETRY_ALL_DOWNS The number of retries to connect all hosts. This parameter is specified in DESCRIPTION. 120 This parameter is equivalent to retryAllDowns in the URL.
OBLB_STRATEGY The LoadBalance strategy. You can specify this parameter in DESCRIPTION or ADDRESS_LIST. RANDOM If you specify this parameter in DESCRIPTION, each host specified in ADDRESS_LIST will use the strategy. If you specify this parameter in ADDRESS_LIST, only the specified hosts will use the strategy and the strategy settings in DESCRIPTION are ignored.
LOAD_BALANCE_STRATEGY The LoadBalance strategy. You can specify this parameter in DESCRIPTION or ADDRESS_LIST. RANDOM This parameter is equivalent to OBLB_STRATEGY.
OBLB_GROUP_STRATEGY The strategy for the access among hosts specified in ADDRESS_LIST. ROTATION Only the ROTATION strategy is supported.
OBLB_BLACKLIST A parameter in DESCRIPTION. The parentheses "()" after OBLB_BLACKLIST contain REMOVE_STRATEGY and APPEND_STRATEGY, which are parameters about the blocklist. OBLB_BLACKLIST=(). The description of the blocklist is contained in the parentheses "()". If you do not specify OBLB_BLACKLIST, the strategies specified for REMOVE_STRATEGY and APPEND_STRATEGY are used.
REMOVE_STRATEGY A parameter of OBLB_BLACKLIST. REMOVE_STRATEGY specifies the strategy for removing a host from the blocklist. REMOVE_STRATEGY=(). These strategies are contained in the parentheses "()". If you do not specify REMOVE_STRATEGY, the default strategy TIMEOUT is used, which specifies to remove the host from the blocklist after a specified period.
APPEND_STRATEGY A parameter of OBLB_BLACKLIST. APPEND_STRATEGY specifies strategies for adding a host to the blocklist. APPEND_STRATEGY=(). These strategies are contained in the parentheses "()". If you do not specify APPEND_STRATEGY, the default strategy NORMAL is used, which specifies to add the host to the blocklist when its connection fails.
NAME A parameter in both APPEND_STRATEGY and REMOVE_STRATEGY. You can use this parameter to specify the names of APPEND_STRATEGY and REMOVE_STRATEGY. The value of NAME must be either one of the specified strings. Otherwise, an error is returned. The only name of REMOVE_STRATEGY is TIMEOUT. Supported names of APPEND_STRATEGY are RETRYDURATION and NORMAL.
TIMEOUT A parameter available when NAME in REMOVE_STRATEGY is TIMEOUT. It specifies the timeout period in milliseconds. 50 This parameter is equivalent to loadBalanceBlacklistTimeout in the URL.
RETRYTIMES One of the parameters available when NAME in APPEND_STRATEGY is RETRYDURATION. This parameter specifies the maximum number of retries within the period specified by DURATION. After the number of connection retries of a host exceeds the specified value, the host is added to the blocklist. You must use this parameter with DURATION.
DURATION One of the parameters available when NAME in APPEND_STRATEGY is RETRYDURATION. When the number of connection retries of a host exceeds the value of RETRYTIMES within the period specified by DURATION, the host is added to the blocklist. You must use this parameter with RETRYTIMES.
ADDRESS_LIST A parameter in DESCRIPTION. You can use this parameter to specify OBLB_STRATEGY for multiple groups of ADDRESS fields or a separate OBLB_STRATEGY. The load balancing strategy for multiple groups of hosts is specified by OBLB_GROUP_STRATEGY. ADDRESS_LIST=(). The description of an ADDRESS group is contained in the parentheses "()". N/A
ADDRESS A parameter in ADDRESS_LIST that specifies the host information, such as the hostname, port, and weight. ADDRESS=(). The description of an ADDRESS is contained in the parentheses "()". N/A
HOST A parameter in ADDRESS that specifies the name of the current host. N/A N/A
PORT A parameter in ADDRESS that specifies the port of the current host. N/A N/A
WEIGHT A parameter in ADDRESS that specifies the weight of the current host. N/A The weight is recognized only when OBLB_STRATEGY is set to SERVERAFFINITY.
PROTOCOL A parameter in ADDRESS that specifies the network protocol used by the current host. N/A At present, this parameter is provided only to be compatible with the configuration format of the Local Naming Parameters file of Oracle.
CONNECT_DATA The name of the database service to connect. N/A This parameter is provided only to be compatible with the configuration format of the Local Naming Parameters file of Oracle.
SERVICE_NAME The schema information. N/A This parameter is provided only to be compatible with the configuration format of the Local Naming Parameters file of Oracle.

Previous topic

Failover and load balancing modes
Last

Next topic

Load balancing strategy configuration methods
Next
on this page
Load balancing strategies
Load balancing group selection strategy
Blocklist strategies
Examples of blocklist strategies
Related parameters