# Async activity is not executing and workflow is completed

**URL:** <https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [November 6, 2023, 6:57pm UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034 "2023-11-06T18:57:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Sandeep](https://community.temporal.io/u/Sandeep)\
**Post date:** [November 6, 2023, 6:57pm UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034/1 "2023-11-06T18:57:25Z")

</div>

Hello Team,

below is the temporal SDK version i am using.

```auto
<dependency>
      <groupId>io.temporal</groupId>
      <artifactId>temporal-sdk</artifactId>
      <version>1.19.1</version>
    </dependency>

```

I am using the java sdk

Below is my Workflow

```auto
@WorkflowInterface
public interface CreateRebetWorkFlow {
  @WorkflowMethod
  public String createRebet(String payload);
}

@ActivityInterface(namePrefix = "CreateRebet_")
public interface CreateRebetActivities {

  public String testA(String payload);
  public String testB(String payload);
  public String testc(String payload);
  public String testd(String payload);
}

```

Below is another work flow

```auto
@WorkflowInterface
public interface ProcessPaymentWorkflow {
  @WorkflowMethod
  String processPayment(String payload);
}

```

Is it possible to execute the async activity and trigger a work flow in the activity.

below is the code for activity impl

```auto
public class CreateRebetActivitiesImpl implements CreateRebetActivities {
public String testA(String payload){
System.out.println("testA")
}
  public String testB(String payload){System.out.println("testB"){
  public String testC(String payload){System.out.println("testc")}
  public String testD(String payload){
  **System.out.println("testD")**
 **// code to Start work flow ProcessPaymentWorkflow**
  }
}

```

Below is the code for workflow impl

```auto
public class CreateRebetWorkFlowImpl implements CreateRebetWorkFlow {

public String createRedeem(String payload) {

	activity.testA("testA");
	activity.testB("testB");
	activity.testC("testC");
	
	
	Promise<String> promise = Async.function(() -> {
		activity.testD("testD");
	}
	

	//If i do promise.get() above async activity is getting triggred and starting the workflow in testD()(ProcessPaymentWorkflow) is getting triggred
	
	//But without promise.get() above async activity is not getting triggred and starting the workflow in testD()(ProcessPaymentWorkflow) is not getting triggred. But the workflow(CreateRebetWorkFlow) is getting completed.
	
	
	// Requirment is once testA,testB,testC gets completed send result to user and testD should be executed Asyn(dont wait for the execution to be completed) which updates certain DB calls.
	
	//What i am expecting is i dont want to wait for the async activity for(testD) to get completed and the underlaying code should be executed and starting ProcessPaymentWorkflow in the testD() should be executed.

}

}

```

---

<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 6, 2023, 10:06pm UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034/2 "2023-11-06T22:06:03Z")

</div>

By design, activities are not executed after workflow completion. So you have to ensure that a workflow function doesn’t return until all its activities are complete. This is not related to how activities are invoked synchronously or asynchronously.

---

<div class="post-metadata">

**Author:** ![Sandeep](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Sandeep](https://community.temporal.io/u/Sandeep)\
**Post date:** [November 7, 2023, 2:54am UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034/3 "2023-11-07T02:54:29Z")

</div>

Thanks a lot @maxim. any suggestions how can we achieve this using temporal?

---

<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 7, 2023, 5:51pm UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034/4 "2023-11-07T17:51:27Z")

</div>

Block the workflow function until all activities complete.

---

<div class="post-metadata">

**Author:** ![Steve\_Frazee](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/steve_frazee/32/7303_2.png) [@Steve\_Frazee](https://community.temporal.io/u/Steve_Frazee)\
**Post date:** [October 6, 2026, 1:11pm UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034/5 "2026-10-06T13:11:56Z")

</div>

I have a related question to this. If an async activity is scheduled, but the workflow completes before it is started, will an activity worker still pick it up to start it?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [October 8, 2026, 9:08pm UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034/6 "2026-10-08T21:08:12Z")

</div>

Depends at which point the execution completes after scheduling activity.  
Scheduling activity creates a task in history service - history service checks on task processing the execution status of the task. If exec at that point is completed history service will drop task and not process it - not move it to matching - activity never executed on sdk worker.

If task moved to matching, matching service once it matches task with sdk poller (so right before task dispatch to your sdk worker), calls history service to record activity started, history then again checks status, and if at that point exec not running, it will tell matching to not dispatch task, and drop the task - activity never executed on sdk worker.

If at that point still exec not closed and matching dispatches task to sdk worker, activity will get executed. Worker does not check status before, but activity worker will get rejection from server once activity worker reports activity completion / failure / or heartbeat - this will not result in retry of activity.

---

<div class="post-metadata">

**Author:** ![bryantkunde](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/bryantkunde/32/8617_2.png) [@bryantkunde](https://community.temporal.io/u/bryantkunde)\
**Post date:** [October 28, 2026, 5:09pm UTC](https://community.temporal.io/t/async-activity-is-not-executing-and-workflow-is-completed/10034/7 "2026-10-28T17:09:54Z")

</div>

For the original requirement, one option is to move the DB work into ProcessPaymentWorkflow as a child workflow, instead of relying on testD after CreateRebetWorkflow returns. Configure the child stub with ParentClosePolicy.PARENT\_CLOSE\_POLICY\_ABANDON, start it with Async.function or Async.procedure, and wait for Workflow.getWorkflowExecution(child).get() before returning the result. That waits for the child to start, not for its work to finish. The default parent close policy is TERMINATE, so ABANDON matters here.

Async.function schedules work but does not keep the parent workflow open by itself. If the parent closes before the activity is dispatched, the activity may never run; if it has already been dispatched, it may run but its completion can be rejected, as described above. If the parent needs the activity’s result or retry outcome, keep the parent open and call promise.get() instead.

Temporal’s Java documentation shows the child-start handshake and explains why waiting for the start is necessary: [Child Workflows - Java SDK | Temporal Documentation](https://docs.temporal.io/develop/java/workflows/child-workflows)
