超级实用!!!!! JAVA 实现突然关闭一个运行的程序,即使这个程序在while(true)死循环中,也可以关闭(用到线程)

因为实例很简单,直接给代码

 1 package com.watch;
 2 
 3 import java.net.ServerSocket;
 4 
 5 public class test  extends Thread{
 6       public volatile boolean exit = false; 
 7       @Override
 8         public void run() {
 9             while(!exit){
10                System.out.println("A");
11             }
12         }
13         
14         public static void main(String[] args) {
15             test t = new test();
16             t.start();
17             t.exit = true; //修改标志位,退出线程
18         }
19 } 
原文地址:https://www.cnblogs.com/smartisn/p/12873462.html