Thread t = CashierThread(); //keep the reference to thread somewhere...
Now instead of a boolean property use built-in interrupted flag:
public void run() {
while(!Thread.currentThread().isInterrupted()) {
//...
}
}
When you want to turn of the thread by clicking on a button simply call:
t.interrupt();
Of course you need to have access to t
variable from the client code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…