0
我試圖找出如何啓動和停止的串行接口。如何啓動/停止和監視Java線程?
class SerialInterface implements Runnable{
// Stream from file
@Override
public void run(){
try {
startInterface();
} catch (IOException ex) {
Logger.getLogger(SerialInterface.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String StartStop){
SerialInterface SerialThread = null;
if (StartStop.equals("start")){
SerialThread = new SerialInterface();
Thread thread1 = new Thread (SerialThread);
thread1.start();
} else {
SerialThread = null;
}
}
private void startInterface() throws IOException { //START DOING STUFF TO SERIAL PORT }
這是行不通的。如何阻止已啓動的線程?