线程的同步与异步

xiaoxiao2021-02-28  143

java代码:

package cn.et.springmvc.lesson05; /** * main方法是主线程 * Thread自定义的线程 * 线程是可以独立运行的的最小单元 * 异步:就是所有线程同时运行 * 同步:就是同一时刻只有一个线程运行 * */ public class TestThread { public static void main(String[] args) throws InterruptedException { Thread t = new Thread(){ public void run() { try { //当前线程睡眠1000millisecond Thread.currentThread().sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("thread"); } }; //t线程开启 t.start(); //等待该线程终止。 t.join(); System.out.println("test"); System.out.println("test1"); System.out.println("test2"); } }

转载请注明原文地址: https://www.6miu.com/read-21415.html

最新回复(0)