We have the following transaction that sends a heartbeat while it is a running. However in certain situations the heartbeat timer never stops, and the system keeps sending heartbeats even if the transaction is not running. Are we doing something incorrectly here? Is there a more sure shot way of stopping the heart beat timer (other than stopping jboss)?
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Asynchronous
public void performUpdate(long requestSettingId) throws exception {
try {
// At this line a new Thread will be created
final Timer timer = new Timer();
// send the first heartbeat
workerService.sendHeartBeat(requestSettingId);
// At this line a new Thread will be created
timer.schedule(new HeartbeatTask(setting.getId()), heartBeatInterval, heartBeatInterval);
try {
//Perform update
//
} finally {
// terminate the HeartbeatTask
timer.cancel();
} catch (Exception e) {
//Notify the task owner of the exception
}
}
}