I tried multiple things to make this work.
- Added
Runtime#runFinalization
before the call to halt(). - Invoked
halt()
inSwingUtilities.invokeAndWait
- Invoked
halt()
inSwingUtilities.invokeLater
None of these worked. Finally,
- Invoked
halt()
in a timer task usingTimer#schedule
This worked and is consistently working till now. Thanks to everyone for the replies.