Stopping a specific java thread

后端 未结 4 1679
猫巷女王i
猫巷女王i 2020-12-03 02:07

I have a button \"addCashier\" which is creating a thread called \"Cashier\" now this thread is just simply generating orders every 4 seconds, a while(true) loop in the run(

4条回答
  •  萌比男神i
    2020-12-03 02:46

    You can store each thread's reference into a HashMap - along with its id or Name as the key. Later when you want to deal with one particular Cashier thread , use the Name or id to fetch the corresponding Thread from the HashMap and call the appropriate logOff() method on it.

提交回复
热议问题