UsbSerial/usbserial/src/main/java/com/felhr/usbserial/AbstractWorkerThread.java

27 wiersze
623 B
Java

package com.felhr.usbserial;
abstract class AbstractWorkerThread extends Thread {
boolean firstTime = true;
private volatile boolean keep = true;
private volatile Thread workingThread;
void stopThread() {
keep = false;
if (this.workingThread != null) {
this.workingThread.interrupt();
}
}
public final void run() {
if (!this.keep) {
return;
}
this.workingThread = Thread.currentThread();
while (this.keep && (!this.workingThread.isInterrupted())) {
doRun();
}
}
abstract void doRun();
}