Java 学习笔记之 线程isAlive方法
isAlive方法:
方法isAlive()功能是判断当前线程是否处于活动状态。
活动状态就是线程启动且尚未终止,比如正在运行或准备开始运行。
public class IsAliveThread extends Thread {
public IsAliveThread() {
System.out.println("begin");
System.out.println("Thread.currentThread().getName() : " + Thread.currentThread().getName());
System.out.println("Thread.currentThread().isAlive() : " + Thread.currentThread().isAlive());
System.out.println("this.getName() : " + this.getName());
System.out.println("this.isAlive() : " + this.isAlive());
System.out.println("end");
}
@Override
public void run() {
System.out.println("run begin");
System.out.println("Thread.currentThread().getName() : " + Thread.currentThread().getName());
System.out.println("Thread.currentThread().isAlive() : " + Thread.currentThread().isAlive());
System.out.println("this.getName() : " + this.getName());
System.out.println("this.isAlive() : " + this.isAlive());
System.out.println("run end");
}
}
public class ThreadRunMain {
public static void main(String[] args) {
testIsAliveThread();
}
public static void testIsAliveThread(){
IsAliveThread ist = new IsAliveThread();
Thread th = new Thread(ist);
System.out.println("Main begin th isAlive = " + th.isAlive());
th.start();
System.out.println("Main end th isAlive = " + th.isAlive());
}
}
运行结果:

Java 学习笔记之 线程isAlive方法的更多相关文章
- Java 学习笔记之 线程isInterrupted方法
线程isInterrupted方法: isInterrupted()是Thread对象的方法,测试线程是否已经中断. public class ThreadRunMain { public stati ...
- Java 学习笔记之 线程interrupted方法
线程interrupted方法: interrupted()是Thread类的方法,用来测试当前线程是否已经中断. public class InterruptThread extends Threa ...
- Java 学习笔记之 线程interrupt方法
线程interrupt方法: interrupt方法是用来停止线程的,但是他的使用效果并不像for+break那样,马上就停止循环. 调用interrupt()其实仅仅是在当前线程中打了一个停止标记, ...
- Java 学习笔记之 线程sleep方法
线程sleep方法: 单主线程使用sleep: Main线程差了2000毫秒. public class MainSleepThread extends Thread{ @Override publi ...
- 0040 Java学习笔记-多线程-线程run()方法中的异常
run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...
- java学习笔记15--多线程编程基础2
本文地址:http://www.cnblogs.com/archimedes/p/java-study-note15.html,转载请注明源地址. 线程的生命周期 1.线程的生命周期 线程从产生到消亡 ...
- java学习笔记14--多线程编程基础1
本文地址:http://www.cnblogs.com/archimedes/p/java-study-note14.html,转载请注明源地址. 多线程编程基础 多进程 一个独立程序的每一次运行称为 ...
- java学习笔记之线程(Thread)
刚开始接触java多线程的时候,我觉得,应该像其他章节的内容一样,了解了生命周期.构造方法.方法.属性.使用的条件,就可以结束了,然而随着我的深入学习了解,我发现java的多线程是java的一个特别重 ...
- JAVA学习笔记16——线程生命周期
当线程被创建并启动以后,它既不是一启动就进入了执行状态,也不是一直处于执行状态,在线程的生命周期中,它要经过新建(New).就绪(Runnable).运行(Running).阻塞(Blocking)和 ...
随机推荐
- 2017 省赛选拨 火车入站 CSU 1757 模拟
1757: 火车入站 Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 512 ...
- hdu 1671 Phone List 字典树模板
Given a list of phone numbers, determine if it is consistent in the sense that no number is the pref ...
- Quartz.Net使用教程
在项目的开发过程中,难免会遇见后需要后台处理的任务,例如定时发送邮件通知.后台处理耗时的数据处理等,这个时候你就需要Quartz.Net了. Quartz.Net是纯净的,它是一个.Net程序集,是非 ...
- .NetCore技术研究-ConfigurationManager在单元测试下的坑
最近在将原有代码迁移.NET Core, 代码的迁移基本很快,当然也遇到了不少坑,重构了不少,后续逐步总结分享给大家.今天总结分享一下ConfigurationManager遇到的一个问题. 先说一下 ...
- 《MySQL实战45讲》学习笔记3——InnoDB为什么采用B+树结构实现索引
索引的作用是提高查询效率,其实现方式有很多种,常见的索引模型有哈希表.有序列表.搜索树等. 哈希表 一种以key-value键值对的方式存储数据的结构,通过指定的key可以找到对应的value. 哈希 ...
- Java中ElasticSearch的删除示例
public class DeleteElasticAPI { private static RestClient restClient; static { restClient=RestClient ...
- Golang 数组 切片 字典 基本知识点
数组 数组的声明 var arrayName [arraySize]dataType eg: var array1 [5]int 在声明数组时,必须指定数组名,数组长度和数组元素的类型. 数组的初始化 ...
- 关于Elasticsearch文档的描述以及如何操作文档的详细总结
文档 什么是文档 在大多数应用中,多数实体或对象可以被序列化为包含键值对的 JSON 对象. 一个 键 可以是一个字段或字段的名称,一个 值 可以是一个字符串,一个数字,一个布尔值, 另一个对象,一些 ...
- tomcat下载镜像地址
镜像地址:http://mirrors.cnnic.cn/apache/tomcat/ typora编写makedown文件 羚羊云api开发:http://doc.topvdn.com/api/in ...
- Android手机QQ文件夹解析
注:切勿修改手机QQ文件夹,以免造成不必要的使用问题及无法修复的数据丢失] 安卓手机QQ tencent文件夹解析 QQ下载的聊天背景:tencent→MobileQQ→system_backgrou ...