zoukankan      html  css  js  c++  java
  • java例程练习(多线程[join()方法])

    public class Test {
    	public static void main(String[] args) {
    		MyThread myThread = new MyThread("m1");
    		myThread.start();   //产生分支,子线程开始执行
    		
    		try{
    			myThread.join();//------等待合并myThread子线程,主线程才开始执行
    		} catch(InterruptedException e) {}
    		
    		for(int i = 1; i <= 10; i++) {
    			System.out.println("I am main thread");
    		}
    	}
    }
    
    class MyThread extends Thread {
    	MyThread(String s) {//给线程起名字的构造方法
    		super(s);
    	}
    	public void run() {
    		for(int i = 0 ; i <= 10; i++) {
    			System.out.println("I'm " + getName());
    			try {
    				sleep(1000);
    			} catch(InterruptedException e) {
    				return;
    			}
    		}
    		
    	}
    }
    

  • 相关阅读:
    mysql-数据库增删改查
    判断,循环
    数组
    html 三种垂直居中
    箭头函数
    Array类型
    object
    JAVA WEB 行业技术
    一个好的程序员
    经典语录
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671694.html
Copyright © 2011-2022 走看看