线程的监控
来源:互联网 发布:网络动漫黑名单 编辑:程序博客网 时间:2024/05/17 04:48
线程监控
public class WW { public static void main(String[] args) { // TODO 自动生成的方法存根 MyThread mt=new MyThread("线程MyThread"); //创建线程类MyThread的对象 System.out.println("-------------------------"); System.out.println("线程MyThread 是否处于运动状态:"+mt.t.isAlive());//查看线程的人状态,判断它是后处于运行状态 try{ System.out.println("-------------------------------"); System.out.println("等待线程结束。。。");//等待线程结束 mt.t.join(); } catch(InterruptedException e){ System.out.println("出现错误,线程中断!"); } System.out.println("------------------------------"); System.out.println("线程MyThread 是否处于运动状态:" +mt.t.isAlive()); System.out.println("----------------------------------"); System.out.println("主线程正在退出。。。"); }}class MyThread implements Runnable{ //创建线程类Runnable,实现Runnable接口 String name; Thread t; MyThread(String th){ //创建属于类Thread得线程的对象 name=th; t=new Thread(this,th); System.out.println("创建线程:"+th); t.start();//启动线程 } public void run(){ //重写方法run(),线程休眠一段时间后退出 try{ Thread.sleep(1000); } catch(InterruptedException e){ System.out.println(name+"中断"); } System.out.println("-------------------------------------"); System.out.println(name+" 正在退出。。。"); }}
运行结果:
知识要点:
1)线程的生命周期
2)线程的优先级和调度策略
3)线程状态的改变
阅读全文
0 0
- 线程的监控
- android应用程序线程的监控
- 监控线程的 Mach 异常
- Java线程池的监控
- 线程监控
- 线程监控
- 线程监控
- 线程监控
- 线程监控
- 线程监控
- 线程监控
- 线程监控
- 线程监控
- 线程监控
- 安全稳定的实现进线程监控
- 安全稳定的实现进线程监控
- 安全稳定的实现进线程监控
- 安全稳定的实现进线程监控
- hbase连接Kerberos报错:msg=Failed to read server kerberos principal row
- sim卡
- Error: That port is already in use——Python Django
- acm
- java 生产者消费者模型(多对多)
- 线程的监控
- 课本题目
- CentOS系统下Gerrit服务器搭建
- 忘记root密码的更改方式及常见错误,附图:user表的正确格式
- 在 Java 中高效使用锁的技巧
- 圆
- 定义无参构造和有参构造方法
- (三)Git的常用操作
- FrameLayout和RadioGroup布局