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)和 ...
随机推荐
- 百度之星初赛A轮 A 度度熊拼三角 贪心
度度熊拼三角 Accepts: 2536 Submissions: 4433 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...
- codeforces 816 E. Karen and Supermarket(树形dp)
题目链接:http://codeforces.com/contest/816/problem/E 题意:有n件商品,每件有价格ci,优惠券di,对于i>=2,使用di的条件为:xi的优惠券需要被 ...
- sed一些常用命令
[转] http://blog.chinaunix.net/uid-20754793-id-177657.html 下面是我学习sed时参照参考书总结的一些常用sed命令,基本上每条语句都进行了调试1 ...
- Integer和Integer常量池
Integer中有个静态内部类 IntegerCache ,里面有个cache[],也就是Integer常量池 大小为一个字节(-128-127). (jdk1.8.0_101)源码 private ...
- Java并发包下的几个API
并发包 (计数器)CountDownLatch (屏障)CyclicBarrier (计数信号量)Semaphore 案例: 需求: 代码: 并发包 (计数器)CountDownLatch Coun ...
- 基于Selenium+Python的web自动化测试框架
一.什么是Selenium? Selenium是一个基于浏览器的自动化测试工具,它提供了一种跨平台.跨浏览器的端到端的web自动化解决方案.Selenium主要包括三部分:Selenium IDE.S ...
- IDEA中的各种快捷键
1.get.set快捷键: Alt+Insert 2.idea补全返回值快捷键 比如写了一个new User(),需要补全前面的User user ctrl+alt+V 3.idea全局搜索: Ctr ...
- Net基础篇_学习笔记_第九天_数组_三个练习
练习一: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...
- C#中using的使用-以FileStream写入文件为例
场景 CS中FileStream的对比以及使用方法: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100396022 关注公众号 ...
- 大数据平台搭建 - cdh5.11.1 - oozie安装
一.简介 oozie是hadoop平台开源的工作流调度引擎,用来管理hadoop作业,属于web应用程序,由oozie server 和oozie client构成. oozie server运行与t ...