码迷,mamicode.com
首页 > 编程语言 > 详细

多线程管理

时间:2020-01-29 20:13:30      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:cat   start   技术   rup   ati   try   throw   row   释放   

线程状态

技术图片

线程相关Api


技术图片

线程终止


技术图片

线程分类


技术图片
守护线程不是自己关闭的情况下,强制终止资源会得不到释放。

package daemon;

public class ThreadDemo4
{
    public static void main(String args[]) throws InterruptedException
    {
        TestThread4 t = new TestThread4();
        t.setDaemon(true);//守护线程开启
        t.start();
        Thread.sleep(2000);
        System.out.println("main thread is exiting");
    }
}
 class TestThread4 extends Thread
{
    public void run() 
    {
        while(true)
        {
            System.out.println("TestThread4" + 
            " is running");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
} 

多线程管理

标签:cat   start   技术   rup   ati   try   throw   row   释放   

原文地址:https://www.cnblogs.com/cstdio1/p/12240855.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!