# Class ExponentialBackOffPolicy (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.ExponentialBackOffPolicy)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.ExponentialBackOffPolicy)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.ExponentialBackOffPolicy)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.ExponentialBackOffPolicy)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.ExponentialBackOffPolicy)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.ExponentialBackOffPolicy)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.ExponentialBackOffPolicy)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.ExponentialBackOffPolicy)

    public class ExponentialBackOffPolicy implements BackOffPolicy

**Deprecated.** *(scheduled to be removed in 1.18). Use [HttpBackOffUnsuccessfulResponseHandler](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler)
with [ExponentialBackOff](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.ExponentialBackOff) instead.*

[Beta](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Beta)   

Implementation of [BackOffPolicy](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.BackOffPolicy) that increases the back off period for each retry attempt
using a randomization function that grows exponentially.

[#getNextBackOffMillis()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_getNextBackOffMillis__) is calculated using the following formula:

randomized_interval =
retry_interval \* (random value in range \[1 - randomization_factor, 1 + randomization_factor\])

In other words [#getNextBackOffMillis()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_getNextBackOffMillis__) will range between the randomization factor
percentage below and above the retry interval. For example, using 2 seconds as the base retry
interval and 0.5 as the randomization factor, the actual back off period used in the next retry
attempt will be between 1 and 3 seconds.

**Note:** max_interval caps the retry_interval and not the randomized_interval.

If the time elapsed since an [ExponentialBackOffPolicy](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy) instance is created goes past
the max_elapsed_time then the method [#getNextBackOffMillis()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_getNextBackOffMillis__) starts returning [BackOffPolicy#STOP](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.BackOffPolicy#com_google_api_client_http_BackOffPolicy_STOP). The elapsed time can be reset by calling [#reset()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_reset__).

Example: The default retry_interval is .5 seconds, default randomization_factor is 0.5,
default multiplier is 1.5 and the default max_interval is 1 minute. For 10 requests the sequence
will be (values in seconds) and assuming we go over the max_elapsed_time on the 10th request:

```
 request#     retry_interval     randomized_interval

 1             0.5                [0.25,   0.75]
 2             0.75               [0.375,  1.125]
 3             1.125              [0.562,  1.687]
 4             1.687              [0.8435, 2.53]
 5             2.53               [1.265,  3.795]
 6             3.795              [1.897,  5.692]
 7             5.692              [2.846,  8.538]
 8             8.538              [4.269, 12.807]
 9            12.807              [6.403, 19.210]
 10           19.210              BackOffPolicy#STOP
 
```

Implementation is not thread-safe.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> ExponentialBackOffPolicy

## Implements

[BackOffPolicy](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.BackOffPolicy)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Fields

### DEFAULT_INITIAL_INTERVAL_MILLIS (deprecated)

    public static final int DEFAULT_INITIAL_INTERVAL_MILLIS

The default initial interval value in milliseconds (0.5 seconds).

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### DEFAULT_MAX_ELAPSED_TIME_MILLIS (deprecated)

    public static final int DEFAULT_MAX_ELAPSED_TIME_MILLIS

The default maximum elapsed time in milliseconds (15 minutes).

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### DEFAULT_MAX_INTERVAL_MILLIS (deprecated)

    public static final int DEFAULT_MAX_INTERVAL_MILLIS

The default maximum back off time in milliseconds (1 minute).

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### DEFAULT_MULTIPLIER (deprecated)

    public static final double DEFAULT_MULTIPLIER

The default multiplier value (1.5 which is 50% increase per back off).

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### DEFAULT_RANDOMIZATION_FACTOR (deprecated)

    public static final double DEFAULT_RANDOMIZATION_FACTOR

The default randomization factor (0.5 which results in a random period ranging between 50%
below and 50% above the retry interval).

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

## Static Methods

### builder() (deprecated)

    public static ExponentialBackOffPolicy.Builder builder()

Returns an instance of a new builder.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy.Builder` |   |

## Constructors

### ExponentialBackOffPolicy() (deprecated)

    public ExponentialBackOffPolicy()

Creates an instance of ExponentialBackOffPolicy using default values. To override the defaults
use [#builder](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_builder_).

- `initialIntervalMillis` is defaulted to [#DEFAULT_INITIAL_INTERVAL_MILLIS](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_DEFAULT_INITIAL_INTERVAL_MILLIS)
- `randomizationFactor` is defaulted to [#DEFAULT_RANDOMIZATION_FACTOR](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_DEFAULT_RANDOMIZATION_FACTOR)
- `multiplier` is defaulted to [#DEFAULT_MULTIPLIER](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_DEFAULT_MULTIPLIER)
- `maxIntervalMillis` is defaulted to [#DEFAULT_MAX_INTERVAL_MILLIS](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_DEFAULT_MAX_INTERVAL_MILLIS)
- `maxElapsedTimeMillis` is defaulted in [#DEFAULT_MAX_ELAPSED_TIME_MILLIS](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_DEFAULT_MAX_ELAPSED_TIME_MILLIS)

### ExponentialBackOffPolicy(ExponentialBackOffPolicy.Builder builder) (deprecated)

    protected ExponentialBackOffPolicy(ExponentialBackOffPolicy.Builder builder)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `builder` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy.Builder` builder |

## Methods

### getCurrentIntervalMillis() (deprecated)

    public final int getCurrentIntervalMillis()

Returns the current retry interval in milliseconds.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getElapsedTimeMillis() (deprecated)

    public final long getElapsedTimeMillis()

Returns the elapsed time in milliseconds since an [ExponentialBackOffPolicy](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy) instance is
created and is reset when [#reset()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_reset__) is called.

The elapsed time is computed using System#nanoTime().

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getInitialIntervalMillis() (deprecated)

    public final int getInitialIntervalMillis()

Returns the initial retry interval in milliseconds.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getMaxElapsedTimeMillis() (deprecated)

    public final int getMaxElapsedTimeMillis()

Returns the maximum elapsed time in milliseconds.

If the time elapsed since an [ExponentialBackOffPolicy](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy) instance is created goes past
the max_elapsed_time then the method [#getNextBackOffMillis()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_getNextBackOffMillis__) starts returning [BackOffPolicy#STOP](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.BackOffPolicy#com_google_api_client_http_BackOffPolicy_STOP). The elapsed time can be reset by calling [#reset()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.ExponentialBackOffPolicy#com_google_api_client_http_ExponentialBackOffPolicy_reset__).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getMaxIntervalMillis() (deprecated)

    public final int getMaxIntervalMillis()

Returns the maximum value of the back off period in milliseconds. Once the current interval
reaches this value it stops increasing.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getMultiplier() (deprecated)

    public final double getMultiplier()

Returns the value to multiply the current interval with for each retry attempt.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getNextBackOffMillis() (deprecated)

    public long getNextBackOffMillis()

Gets the number of milliseconds to wait before retrying an HTTP request. If #STOP is
returned, no retries should be made.

This method calculates the next back off interval using the formula: randomized_interval =
retry_interval +/- (randomization_factor \* retry_interval)

Subclasses may override if a different algorithm is required.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | the number of milliseconds to wait when backing off requests, or #STOP if no more retries should be made |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### getRandomizationFactor() (deprecated)

    public final double getRandomizationFactor()

Returns the randomization factor to use for creating a range around the retry interval.

A randomization factor of 0.5 results in a random period ranging between 50% below and 50%
above the retry interval.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isBackOffRequired(int statusCode) (deprecated)

    public boolean isBackOffRequired(int statusCode)

Determines if back off is required based on the specified status code.

The idea is that the servers are only temporarily unavailable, and they should not be
overwhelmed when they are trying to get back up.

The default implementation requires back off for 500 and 503 status codes. Subclasses may
override if different status codes are required.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `statusCode` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### reset() (deprecated)

    public final void reset()

Sets the interval back to the initial retry interval and restarts the timer.