# Are activity interceptors the way to go to perform side effects when retrying more than x attempts?

**URL:** <https://community.temporal.io/t/are-activity-interceptors-the-way-to-go-to-perform-side-effects-when-retrying-more-than-x-attempts/16026>\
**Category:** Community Support\
**Tags:** java-sdk, activity\
**Created:** [January 10, 2025, 3:23pm UTC](https://community.temporal.io/t/are-activity-interceptors-the-way-to-go-to-perform-side-effects-when-retrying-more-than-x-attempts/16026 "2025-01-10T15:23:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cec](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/cec/32/6451_2.png) [@cec](https://community.temporal.io/u/cec)\
**Post date:** [January 10, 2025, 3:23pm UTC](https://community.temporal.io/t/are-activity-interceptors-the-way-to-go-to-perform-side-effects-when-retrying-more-than-x-attempts/16026/1 "2025-01-10T15:23:59Z")

</div>

Hi,

I would like to know if ActivityInboundCallsInterceptorBase is the way to go in order to execute custom logic if an activity encounters a certain error for more than x attempts.

Basically I would like to for my activities to keep retrying, so that technicians can deploy needed fixes and have the workflows progress forward, but at the same time, I would like to notify certain people if more than X attempts happened.

Thanks 🙂

I am struggling with how to deal with intermittent failures.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [January 10, 2025, 6:23pm UTC](https://community.temporal.io/t/are-activity-interceptors-the-way-to-go-to-perform-side-effects-when-retrying-more-than-x-attempts/16026/2 "2025-01-10T18:23:08Z")

</div>

You can access the number of attempts in ActivityInboundCallsInterceptor and perform the necessary notification.

---

<div class="post-metadata">

**Author:** ![cec](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/cec/32/6451_2.png) [@cec](https://community.temporal.io/u/cec)\
**Post date:** [January 10, 2025, 7:12pm UTC](https://community.temporal.io/t/are-activity-interceptors-the-way-to-go-to-perform-side-effects-when-retrying-more-than-x-attempts/16026/3 "2025-01-10T19:12:41Z")

</div>

Thanks for the reply.  
I have a couple of questions regarding how to implement this.

_public void init(ActivityExecutionContext context)_ gives me access to the attempt by first getting _ActivityInfo_.  
However I don’t have this information in _public ActivityOutput execute(ActivityInput input)_.  
From the two methods, it seems to me that I’m supposed to store locally the number of attempts of the activity and then use that value in _execute_.

Is this correct?

Also, could you clarify the lifecycle of the interceptor?

Finally, I’ve seen @Experimental annotation in the SDK, do you recommend using it?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [January 10, 2025, 7:41pm UTC](https://community.temporal.io/t/are-activity-interceptors-the-way-to-go-to-perform-side-effects-when-retrying-more-than-x-attempts/16026/4 "2025-01-10T19:41:39Z")

</div>

The inbound interceptor is created by [WorkerInterceptor.interceptActivity](https://github.com/temporalio/sdk-java/blob/ee6ce186ef401c8093233829179086ddb28aee92/temporal-sdk/src/main/java/io/temporal/common/interceptors/WorkerInterceptor.java#L97) method which is called per activity invocation. So you can create an instance of your interceptor per activity invocation, which means you can use the interceptor fields to pass data from one method to another.

It is also possible to use `Activity.getExecutionContext` in the `execute` method to get the context.
