Skip to main content

How to set Activity Retry Options in Java

To set a Retry Policy, known as the Retry Options in Java, use ActivityOptions.newBuilder.setRetryOptions().

  • Type: RetryOptions

  • Default: Server-defined Activity Retry policy.

  • With ActivityStub

    private final ActivityOptions options =
    ActivityOptions.newBuilder()
    // note that either StartToCloseTimeout or ScheduleToCloseTimeout are
    // required when setting Activity options.
    .setStartToCloseTimeout(Duration.ofSeconds(5))
    .setRetryOptions(
    RetryOptions.newBuilder()
    .setInitialInterval(Duration.ofSeconds(1))
    .setMaximumInterval(Duration.ofSeconds(10))
    .build())
    .build();
  • With WorkflowImplementationOptions

    WorkflowImplementationOptions options =
    WorkflowImplementationOptions.newBuilder()
    .setActivityOptions(
    ImmutableMap.of(
    "EmailCustomerGreeting",
    ActivityOptions.newBuilder()
    // note that either StartToCloseTimeout or ScheduleToCloseTimeout are
    // required when setting Activity options.
    .setStartToCloseTimeout(Duration.ofSeconds(5))
    .setRetryOptions(
    RetryOptions.newBuilder()
    .setDoNotRetry(NullPointerException.class.getName())
    .build())
    .build()))
    .build();