zoukankan      html  css  js  c++  java
  • 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());
        }
    }

    运行结果:

  • 相关阅读:
    PDA固定资产条码管理系统软件-解决固定资产实物清查的瓶颈问题,大大提高清查效率
    互联网+下PDA移动智能手持POS超市收银开单软件
    搭建免费代理池
    解析库beautifulsoup
    爬取汽车之家新闻
    请求库之requests库
    网络状态码301与302
    正向代理与反向代理
    垃圾回收机制详解
    HTTP协议详解
  • 原文地址:https://www.cnblogs.com/AK47Sonic/p/7663583.html
Copyright © 2011-2022 走看看