# How to distinguish between parallel Promises that succeeded and failed?

**URL:** <https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [May 3, 2022, 2:16pm UTC](https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604 "2022-05-03T14:16:12Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Shai\_Zaban](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/shai_zaban/32/1999_2.png) [@Shai\_Zaban](https://community.temporal.io/u/Shai_Zaban)\
**Post date:** [May 18, 2022, 5:38am UTC](https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604/21 "2022-05-18T05:38:42Z")

</div>

thanks Maxim,

```auto
runBlocking 

```

solved it, as follows (this is an activity function):

```auto
    override fun updateSessionToDB(bulkId: String, sessionUpdateRequest: SessionUpdateDbRequest): SessionUpdateDbResponse {
        val sessionId = sessionUpdateRequest.sessionId
        val sessionResponse = runBlocking {
            agendaService.updateSessionToDbForBulk(
                accountId = sessionUpdateRequest.accountId,
                eventId = sessionUpdateRequest.eventId,
                sessionId = sessionId,
                patchSessionRequest = sessionUpdateRequest.data
            )
        }
        return sessionResponse
    }

```

in that way, the activity does not have to be suspended and it can call a suspend function (updateSessionToDbForBulk). in case of parallel, I call Kotlin’s “async” within the “runBlocking”.

---

<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:** [May 18, 2022, 6:15pm UTC](https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604/22 "2022-05-18T18:15:01Z")

</div>

Note that you can implement an activity asynchronously using [DoNotCompleteOnReturn](https://docs.temporal.io/docs/java/activities/#asynchronous-activity-completion).

---

<div class="post-metadata">

**Author:** ![Shai\_Zaban](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/shai_zaban/32/1999_2.png) [@Shai\_Zaban](https://community.temporal.io/u/Shai_Zaban)\
**Post date:** [May 18, 2022, 10:06pm UTC](https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604/23 "2022-05-18T22:06:07Z")

</div>

thanks for the replies.

back to workflows, I have the following question:  
in your documentation it is said that:

> “There is no need in explicit synchronization because multi-threaded code inside a Workflow is executed one thread at a time and under a global lock”

but in your example we can see that ([Temporal Java SDK developer's guide | Temporal Documentation](https://docs.temporal.io/docs/java/activities/?_ga=2.42133797.1061994847.1652688625-731044863.1649854002#:~:text=//%20Download%20all%20files%20in%20parallel). ):

```auto
      // Download all files in parallel.
      for (String sourceFilename : args.getSourceFilenames()) {
        Promise<String> localName =
            Async.function(activities::download, args.getSourceBucketName(), sourceFilename);
        localNamePromises.add(localName);
      }

```

my questions are:

1. are the downloads of the files really parallel, or only concurrent?
2. if I’d like to limit the number of threads opened by Async.function, how would you suggest to do that?
3. in the documentation you say:

> “Do not use any mutable global variables in your Workflow implementations. This will assure that multiple Workflow instances are fully isolated”

what do you mean by “global variables”. can’t I use a list\map as a workflow variable? in this example moneybatch we can see such mutable (Set) collection

Thanks,  
Shai

---

<div class="post-metadata">

**Author:** ![Shai\_Zaban](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/shai_zaban/32/1999_2.png) [@Shai\_Zaban](https://community.temporal.io/u/Shai_Zaban)\
**Post date:** [May 19, 2022, 9:49pm UTC](https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604/24 "2022-05-19T21:49:50Z")

</div>

adding another question to this thread:

if some workflow has default execution timeout (which is infinite), and the pod on which it’s running on crashes, will it be retried? if yes - how and when? if not - should I set the timeout to some finite time?

Thanks,  
Shai

---

<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:** [May 19, 2022, 9:56pm UTC](https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604/25 "2022-05-19T21:56:00Z")

</div>

Could you please ask in a separate thread? It really helps to ask each independent question in separate one.

[Previous page](https://community.temporal.io/t/how-to-distinguish-between-parallel-promises-that-succeeded-and-failed/4604.md?page=1)
