# Open long-running workflows waiitng on workflow.await()

**URL:** <https://community.temporal.io/t/open-long-running-workflows-waiitng-on-workflow-await/8349>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [May 25, 2023, 2:42am UTC](https://community.temporal.io/t/open-long-running-workflows-waiitng-on-workflow-await/8349 "2023-05-25T02:42:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhijith\_K](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/abhijith_k/32/3822_2.png) [@Abhijith\_K](https://community.temporal.io/u/Abhijith_K)\
**Post date:** [May 25, 2023, 2:42am UTC](https://community.temporal.io/t/open-long-running-workflows-waiitng-on-workflow-await/8349/1 "2023-05-25T02:42:30Z")

</div>

Consider we have million workflows waiting on a signal() / user input. In this case, **especially in java** where threads are costly, we end up having million workflow instances/runIDs waiting on a signal.

1. Does this mean we will be having all these million workflow instances/runIDs as threads in suspended state and in memory?
2. WorkerFactoryOptions.Builder setWorkflowCacheSize​(int workflowCacheSize) and  
WorkerFactoryOptions.Builder setMaxWorkflowThreadCount​(int maxWorkflowThreadCount) does help in caching and avoiding creation/resuming of workflows from replay, but keeping millions of workflows in consideration, what would be the acceptable values?
3. If for some reasons we hit limits of threads and are purged/killed, and the signals arrive after few days, will the workflow be still restarted and execution is guranteed? If yes, how is this achieved?

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [May 25, 2023, 5:53pm UTC](https://community.temporal.io/t/open-long-running-workflows-waiitng-on-workflow-await/8349/4 "2023-05-25T17:53:24Z")

</div>

Hello @Abhijith_K

> 1. Does this mean we will be having all these million workflow instances/runIDs as threads in suspended state and in memory?

No, your workers created from same worker factory can utilize up to MaxWorkflowThreadCount. Worker can process however many many more workflow executions as it has thread eviction.

> 1. WorkerFactoryOptions.Builder setWorkflowCacheSize​(int workflowCacheSize) and  
> WorkerFactoryOptions.Builder setMaxWorkflowThreadCount​(int maxWorkflowThreadCount) does help in caching and avoiding creation/resuming of workflows from replay, but keeping millions of workflows in consideration, what would be the acceptable values?

It also plays a role, the number of pollers and ConcurrentWorkflowTasks and ConcurrentActivityTasks among others (please see [Developer's guide - Worker performance | Temporal Documentation](https://docs.temporal.io/dev-guide/worker-performance))

The configuration will depend on the workflow’s nature. How many of those workflows will be concurrently running? or do they be mostly sleeping/awaiting to be signaled? and the number of worker replicas too.

> 1. If for some reasons we hit limits of threads and are purged/killed, and the signals arrive after few days, will the workflow be still restarted and execution is guranteed? If yes, how is this achieved?

The [workflow history](https://docs.temporal.io/workflows#event-history) is persisted in the database. If a workflow execution is evicted from cache (or your worker crashes) , the same or another worker will poll the tasks, and if it can not find the workflow execution in cache (metric [sticky\_cache\_miss](https://docs.temporal.io/references/sdk-metrics#sticky_cache_miss)) the worker will poll the workflow history and [replay](https://docs.temporal.io/workflows#replays) it to recover the workflow execution state and continue from there.

Let me know if it helps,

---

<div class="post-metadata">

**Author:** ![Abhijith\_K](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/abhijith_k/32/3822_2.png) [@Abhijith\_K](https://community.temporal.io/u/Abhijith_K)\
**Post date:** [May 26, 2023, 7:55am UTC](https://community.temporal.io/t/open-long-running-workflows-waiitng-on-workflow-await/8349/5 "2023-05-26T07:55:40Z")

</div>

Thanks @antonio.perez for the help.
