How to stop a thread created by implementing runnable interface?

前端 未结 6 2217
独厮守ぢ
独厮守ぢ 2020-11-27 13:08

I have created class by implementing runnable interface and then created many threads(nearly 10) in some other class of my project.
How to stop some of those threads?

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 14:04

    Thread.currentThread().isInterrupted() is superbly working. but this code is only pause the timer.

    This code is stop and reset the thread timer. h1 is handler name. This code is add on inside your button click listener. w_h =minutes w_m =milli sec i=counter

     i=0;
                w_h = 0;
                w_m = 0;
    
    
                textView.setText(String.format("%02d", w_h) + ":" + String.format("%02d", w_m));
                            hl.removeCallbacksAndMessages(null);
                            Thread.currentThread().isInterrupted();
    
    
                            }
    
    
                        });
    
    
                    }`
    

提交回复
热议问题