# Activity Cancellation Heartbeat

**URL:** <https://community.temporal.io/t/activity-cancellation-heartbeat/13623>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [September 20, 2024, 10:15pm UTC](https://community.temporal.io/t/activity-cancellation-heartbeat/13623 "2024-09-20T22:15:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andres\_Felipe\_Benavi](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/andres_felipe_benavi/32/3904_2.png) [@Andres\_Felipe\_Benavi](https://community.temporal.io/u/Andres_Felipe_Benavi)\
**Post date:** [September 20, 2024, 10:15pm UTC](https://community.temporal.io/t/activity-cancellation-heartbeat/13623/1 "2024-09-20T22:15:16Z")

</div>

Hey!

I have a doubt, I added heartbeat to my activities in order to detect cancelations in order to be able to stop the activity process and execute some kind of gracefull shutdown

But I have the next question, is it mandatory to define heartbeat timeout for the activities?, I wonder this because I executed my workflows and the activities are properly pushing the hearbeat and also catching the cancelation properly

Is it mandatory to set the hearbeat timeout or is it optional?

---

<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:** [September 21, 2024, 4:17pm UTC](https://community.temporal.io/t/activity-cancellation-heartbeat/13623/2 "2024-09-21T16:17:27Z")

</div>

Java SDK [heartbeats once a minute](https://github.com/temporalio/sdk-java/blob/eabd51fbdc62a7435c8f4d8dc1ac24da26f6022d/temporal-sdk/src/main/java/io/temporal/worker/WorkerOptions.java#L66) when heartbeat timeout is not set. I would recommend setting the heartbeat timeout. Without it, the activity will not timeout for the duration of StartToClose timeout in the case of worker crashes.
