# Execute activity from interceptor fails - \[Called from non workflow or workflow callback thread\]

**URL:** <https://community.temporal.io/t/execute-activity-from-interceptor-fails-called-from-non-workflow-or-workflow-callback-thread/10191>\
**Category:** Community Support\
**Tags:** java-sdk, activity, exception, interceptor\
**Created:** [November 24, 2023, 10:02pm UTC](https://community.temporal.io/t/execute-activity-from-interceptor-fails-called-from-non-workflow-or-workflow-callback-thread/10191 "2023-11-24T22:02:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julian\_Ocampo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/julian_ocampo/32/4591_2.png) [@Julian\_Ocampo](https://community.temporal.io/u/Julian_Ocampo)\
**Post date:** [November 24, 2023, 10:02pm UTC](https://community.temporal.io/t/execute-activity-from-interceptor-fails-called-from-non-workflow-or-workflow-callback-thread/10191/1 "2023-11-24T22:02:22Z")

</div>

Hi Temporal Team,

When I try to run an activity to notify a block of an activity within a workflow, I receive the following exception:  
“Called from non workflow or workflow callback thread”

What should be the correct way to execute an activity within an interceptor? I appreciate the help.

**Interceptor implementation**

```auto
public class ActivityInboundCallsInterceptor extends ActivityInboundCallsInterceptorBase {
    private final Logger log;
    private final Integer maxRetryBeforeNotify;
    private static final Set<String> processedKeys = Collections.synchronizedSet(new HashSet<>());
    private ActivityExecutionContext activityExecutionContext;
    Class<?>[] workflowImplementationForNotify;

    public ActivityInboundCallsInterceptor(io.temporal.common.interceptors.ActivityInboundCallsInterceptor next, Integer maxRetryBeforeNotify, Class<?>... workflowImplementationForNotify) {
        super(next);
        this.log = Workflow.getLogger(ActivityInboundCallsInterceptor.class);
        this.maxRetryBeforeNotify = maxRetryBeforeNotify;
        this.workflowImplementationForNotify = workflowImplementationForNotify;
    }

    @Override
    public void init(ActivityExecutionContext context) {
        this.activityExecutionContext = context;
        super.init(context);
    }

    @Override
    public ActivityOutput execute(ActivityInput input) {
        ActivityOutput output = null;
          try {
              output = super.execute(input);
              processedKeys.remove(this.activityExecutionContext.getInfo().getWorkflowId());
          } catch (Exception ex) {
              if (this.activityExecutionContext.getInfo().getAttempt() == maxRetryBeforeNotify
                      && !processedKeys.contains(this.activityExecutionContext.getInfo().getWorkflowId())) {
                  log.info("[{}][{}] Sending activity error notification. {}", getClass().getCanonicalName(), Workflow.getInfo().getRunId(), activityExecutionContext.getInfo().getWorkflowId());

                  processedKeys.add(this.activityExecutionContext.getInfo().getWorkflowId());
               
                  SendMessageToSlackActivityImpl.builder()
                          .slackRepository(Objects.requireNonNull(ServiceContext.getBean(SlackRepository.class)))
                          .build()
                          .execute(SendMessageToSlackActivity.Arguments.builder()
                                  .key("LOGISTICS_GENERAL_ERROR")
                                  .data(slackMessageData)
                                  .build());
              }
              throw new RuntimeException(ex);
          }

      return output;
  }

```

```auto
  "message": "Called from non workflow or workflow callback thread",
  "source": "JavaSDK",
   "stackTrace": "io.temporal.internal.sync.DeterministicRunnerImpl.currentThreadInternal(DeterministicRunnerImpl.java:97)\nio.temporal.internal.sync.WorkflowInternal.getRootWorkflowContext(WorkflowInternal.java:405)\nio.temporal.internal.sync .WorkflowInternal.getWorkflowInfo(WorkflowInternal.java:478)\nio.temporal.workflow.Workflow.getInfo(Workflow.java:340)\ncom.becleverman.salesandsubscriptionsservice.temporal.interceptors.ActivityInboundCallsInterceptor.execute(ActivityInboundCallsInterceptor.java:44)\ nio.temporal.internal.activity.POJOActivityTaskHandler$POJOActivityImplementation.execute(...

```

---

<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:** [November 24, 2023, 10:24pm UTC](https://community.temporal.io/t/execute-activity-from-interceptor-fails-called-from-non-workflow-or-workflow-callback-thread/10191/2 "2023-11-24T22:24:18Z")

</div>

You are trying to execute an activity from an _Activity Interceptor_. The Activity Interceptor executes in the context of the activity. Activities are not allowed to call other activities, thus the failure.

You can call activities (and execute any other workflow code) from a Workflow Interceptor.
