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);
            }
        }
    }
  • 相关阅读:
    Java学习之路
    ofo开锁共享平台
    Texstudio
    我的母亲 (老舍)
    Excel数据透视表
    Excel分类汇总与数据有效性
    Tomcat源码分析
    证明:在任意六人的聚会中,要么有三人曾经认识,要么有三人不曾认识
    琅琊榜读书笔记
    选择排序可视化
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2861090.html
Copyright © 2011-2022 走看看