zoukankan      html  css  js  c++  java
  • Java基础多线程之join抢夺CPU执行权直到该线程结束。

    class JoinThreadDemo
    {
        public static void main(String[] args)
        {
            JoinThread joinThread = new JoinThread();
            
            Thread t1 = new Thread(joinThread,"t1");
            Thread t2 = new Thread(joinThread,"t2");
            
            t1.start();
            
            try
            {
                t1.join();
            }
            catch(Exception e)
            {
                System.out.println(Thread.currentThread().getName()+" Exception");
            }
            
            t2.start();
            
            for(int x = 0;x<80;x++)
            {
                System.out.println(Thread.currentThread().getName() + " run:"+x);
            }
            
            System.out.println("over");
        }
    }

    class JoinThread implements Runnable
    {
        public void run()
        {
            for(int x = 0;x<70;x++)
            {
                System.out.println(Thread.currentThread().getName()+" run:"+x);
            }
        }
    }
  • 相关阅读:
    (摘)Zebra打印机异常处理
    (摘)Chart Y轴设置为百分比
    关于ZFS、GPT、4K、Geom Label的一些说明
    (转)ASP.NET性能优化之分布式Session
    (转)WebService的事务处理
    SqlSever分页查询,仅扫描一次表
    (转)对.net系统架构改造的一点经验和教训
    字典树
    Ajax
    Lunix 命令
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2861090.html
Copyright © 2011-2022 走看看