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);
            }
        }
    }
  • 相关阅读:
    xiong_6博客迁址
    调用百度地图获取地理位置
    fastadmin 接口开发注意事项
    fastadmin下拉选择框数据生成
    fastadmin 模型篇
    fastadmin跨数据库配置模型
    Git学习笔记#2-创建版本库与提交文件
    Git学习笔记#1-基本概念
    科目一知识点汇总
    Mysql学习笔记#6-约束
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2861090.html
Copyright © 2011-2022 走看看