kopia lustrzana https://github.com/felHR85/UsbSerial
Merge pull request #228 from t2t-sonbui/fix-write-thread
Fix Write Thread does not stop when close portpull/240/head
commit
5eddda99e9
|
@ -3,13 +3,21 @@ package com.felhr.usbserial;
|
||||||
abstract class AbstractWorkerThread extends Thread {
|
abstract class AbstractWorkerThread extends Thread {
|
||||||
boolean firstTime = true;
|
boolean firstTime = true;
|
||||||
private volatile boolean keep = true;
|
private volatile boolean keep = true;
|
||||||
|
private volatile Thread workingThread;
|
||||||
|
|
||||||
void stopThread() {
|
void stopThread() {
|
||||||
keep = false;
|
keep = false;
|
||||||
|
if (this.workingThread != null) {
|
||||||
|
this.workingThread.interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void run() {
|
public final void run() {
|
||||||
while (keep) {
|
if (!this.keep) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.workingThread = Thread.currentThread();
|
||||||
|
while (this.keep && (!this.workingThread.isInterrupted())) {
|
||||||
doRun();
|
doRun();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ public class SerialBuffer
|
||||||
} catch (InterruptedException e)
|
} catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
byte[] dst;
|
byte[] dst;
|
||||||
|
|
Ładowanie…
Reference in New Issue