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);
            }
        }
    }
  • 相关阅读:
    操作系统--进程间同步
    操作系统--进程间通信
    LeetCode-- Unique Binary Search Trees II
    STL源码--序列容器(一)
    操作系统--用户级线程和内核级线程
    非洲孩子
    寻找最大数(三)
    找点
    心急的C小加
    1044 拦截导弹——http://codevs.cn/problem/1044/
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2861090.html
Copyright © 2011-2022 走看看