Can you send a cancellation request instead of terminating the workflow?
You can learn about the difference here:
So just wanted to understand what is the best way to do cleanup activities?
With cancellation, Inside the activity, you can handle ActivityCompletionException
and do any additional cleanup https://github.com/temporalio/samples-java/blob/f107c79e29453ecd43dce522dfd1c980439b3762/core/src/main/java/io/temporal/samples/hello/HelloCancellationScope.java#L207
The same in your workflow code , you can handle the exception and create a detached scope to run an activity
Antonio