public static void main(String[] args) {
log.error("主线程:{}", Thread.currentThread().getName());
InnerRunnable myRunnable = new InnerRunnable();
Thread thread1 = new Thread(myRunnable,"线程1");
thread1.start();
//Executor3();
log.error("中断线程1");
//thread1.isInterrupted();
thread1.stop();
log.error("中断是否成功",thread1.currentThread().getName());
}
public static class InnerRunnable implements Runnable{
public void run(){
try{
Integer i =1;
while(i<60){
log.error("线程{}内部的i:{}", Thread.currentThread().getName(),i);
i++;
}
}catch(Exception e){
log.error("线程被中断", Thread.currentThread().getName());
}
}
}
public static void ExecutorsM()
停止线程方法尝试和总结
最新推荐文章于 2022-04-30 17:26:44 发布