JUC学习-13-isAlive

JUC学习-13-isAlive

判断线程是否存活(还没有运行完毕)

线程存活(没有运行完毕) 返回true

pubilc final native boolean isAlive()

代码例子:

class JoinThread {
	static int value = 1;

	public static void main(String[] args) throws InterruptedException {
		Thread t = new Thread(() -> {
		value = 10;
			System.out.println("线程Runnable");
		});
		t.start();
		System.out.println(t.isAlive());
		// 使用join方法
		t.join();
		System.out.println(t.isAlive());
		System.out.println("主线程: " + value);
	}
}

说明:

image

执行完t.join()后,子线程已经运行完毕,此时isAlive返回值为false

posted @ 2025-07-09 11:21  skystrivegao  阅读(12)  评论(0)    收藏  举报