多线程join,强制执行完
生活随笔
收集整理的這篇文章主要介紹了
多线程join,强制执行完
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
想象成插隊(duì)
package com.wuming.state; //測(cè)試join public class TestJoin implements Runnable{/*** When an object implementing interface <code>Runnable</code> is used* to create a thread, starting the thread causes the object's* <code>run</code> method to be called in that separately executing* thread.* <p>* The general contract of the method <code>run</code> is that it may* take any action whatsoever.** @see Thread#run()*/@Overridepublic void run() {for (int i = 0; i < 100; i++) {System.out.println("線程vip來了"+i);}}public static void main(String[] args) throws InterruptedException {//啟動(dòng)我們的線程TestJoin testJoin = new TestJoin();Thread thread = new Thread(testJoin);thread.start();//主線程for (int i = 0; i < 1000; i++) {if (i==200){thread.join();//插隊(duì)}System.out.println("main"+i);}} }總結(jié)
以上是生活随笔為你收集整理的多线程join,强制执行完的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言 全局变量和局部变量区别 - C语
- 下一篇: 封装之详细详解