Java如何检查一个线程停止或没有? 解决方法 下面的示例演示如何使用 isAlive()方法检查一个线程是否停止. public class Main { public static void main(String[] argv) throws Exception { Thread thread = new MyThread(); thread.start(); if (thread.isAlive()) { System.out.println("Thread has not finish…
自己在做实验性小项目的时候,发现自己遇到一个问题:如何控制线程的"死亡"? 首先,如何开启一个线程呢? 最简单的代码: public class Main { public static void main(String[] args) { Thread thread = new Thread(new Runnable() { @Override public void run() { System.out.println("当前线程:" + Thread.curr…