To start, your ShutdownHook works great. Now about the dead ends.
Do you know if there are any stop hooks registered in your application?
I am sure that there are no such things, because if in some third part there is another dead end, your application will be blocked even without your hook. I believe that this is not a fact, because you are complaining about your code, so without your hook it works fine and therefore there are no third-party hooks.
Your dead end is in one of these calls:
try {UIUtil.cancelAllTasks();} catch (Throwable e) {e.printStackTrace();}; try {mehad.io.port.ScannerManager.disableAutoHandshake();} catch (Throwable e) {e.printStackTrace();}; try {mehad.io.port.ComPortInterface.getInstance().close();} catch (Throwable e) {e.printStackTrace();}; try { if (lockStream != null) { lockStream.close(); }
The fact that they are wrapped in a try / catch block does not prevent them from being stuck.
There is no code in these methods. Even lockStream.close (); may block execution.
Remove them one of mine and see what causes the lock. Then go inside and see what actually blocks them.
source share