Continually try to force-interrupt an event thread if it does not join in a timely fashion

This commit is contained in:
Will Hedgecock 2022-02-14 11:51:29 -06:00
parent a9444ffbad
commit faffe075c8
1 changed files with 7 additions and 5 deletions

View File

@ -2,7 +2,7 @@
* SerialPort.java * SerialPort.java
* *
* Created on: Feb 25, 2012 * Created on: Feb 25, 2012
* Last Updated on: Jan 28, 2022 * Last Updated on: Feb 14, 2022
* Author: Will Hedgecock * Author: Will Hedgecock
* *
* Copyright (C) 2012-2022 Fazecast, Inc. * Copyright (C) 2012-2022 Fazecast, Inc.
@ -1764,11 +1764,13 @@ public final class SerialPort
setEventListeningStatus(portHandle, false); setEventListeningStatus(portHandle, false);
try try
{
do
{ {
serialEventThread.join(500); serialEventThread.join(500);
if (serialEventThread.isAlive()) if (serialEventThread.isAlive())
serialEventThread.interrupt(); serialEventThread.interrupt();
serialEventThread.join(); } while (serialEventThread.isAlive());
} }
catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
serialEventThread = null; serialEventThread = null;