Thread seams to be aborted some times

I’am developing an OpenHAB binding which receives serial port events and sends answers using a thread. But sometimes this thread seams to be aborted without any exception.

I’ve uploaded the code to my GitHub profie:

The tread runs in the OpenDoor method. When the error occurs the first line seams to be executed, but the log at line 279 doesn’t appear in the log. I also don’t get a error log from the try catch.

What could cause such a problem?

How do you know if the thread is aborted versus blocked?

The open door command is sent (the relay opens) but then the thread seams to stop, so I don’t think the thread is blocked by the write or flush command. I’ve now changed catch(Exception e) to catch(Throwable e) because I read that thread.stop raises an Error and not an Exception and would not be catched. I’ve also changed the thread priority to HIGH. Do you have another idea what could help debugging this problem?

There is still a possibility that the flush never returns. It would explain the symptoms you are seeing (no exceptions).

After the thread stops running, you could get a thread dump of the process and see if the thread stack shows up in that dump. That would provide evidence about whether the thread died or is blocked.

Another option is to run openhab with a debugger (or use remote debugging) and step through those lines.