Java 实例 - 查看线程是否存活
Java 教程
· 2019-02-11 22:58:48
以下实例演示了如何通过继承 Thread 类并使用 isAlive() 方法来检测一个线程是否存活:
TwoThreadAlive.java 文件
public class TwoThreadAlive extends Thread {
public void run() {
for (int i = 0; i < 10; i++) {
printMsg();
}
}
public void printMsg() {
Thread t = Thread.currentThread();
String name = t.getName();
System.out.println("name=" + name);
}
public static void main(String[] args) {
TwoThreadAlive tt = new TwoThreadAlive();
tt.setName("Thread");
System.out.println("before start(), tt.isAlive()=" + tt.isAlive());
tt.start();
System.out.println("just after start(), tt.isAlive()=" + tt.isAlive());
for (int i = 0; i < 10; i++) {
tt.printMsg();
}
System.out.println("The end of main(), tt.isAlive()=" + tt.isAlive());
}
}
以上代码运行输出结果为:
before start(), tt.isAlive()=false just after start(), tt.isAlive()=true name=main name=Thread name=main name=main name=main name=main name=main name=main name=main name=main name=main name=Thread name=Thread name=Thread name=Thread name=Thread The end of main(), tt.isAlive()=true name=Thread name=Thread name=Thread name=Thread
点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html
Ext JS源码分析与开发实例宝典
彭仁夔 / 电子工业出版社 / 2010-1 / 78.00元
《Ext JS源码分析与开发实例宝典》从Ext JS实现的基本功能开始讲解,从两个方面对Ext JS进行整体上的概述,让读者从宏观上去把握ExtJS框架。接下来讲解Ext JS核心基础知识,包括事件机制、模板模型、数据模型以及对类、函数、字符串、日期、数组及定时任务这6个类进行扩展。然后讲解Ext JS基于元素的开发,包括动画特效和拖曳实现等。最后深入讲解组件的开发,对布局、模型及4大组件一一进行......一起来看看 《Ext JS源码分析与开发实例宝典》 这本书的介绍吧!