首页 > 编程语言 > 详细

JAVA 多线程

时间:2020-09-04 23:49:45      阅读:103      评论:0      收藏:0      [点我收藏+]
public class MyThread extends Thread {

    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("MyThread " + i);

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        MyThread thread = new MyThread();
        thread.start();

        for (int i = 0; i < 100; i++) {
            System.out.println("main " + i);

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

}

运行结果

main 0
MyThread 0
main 1
MyThread 1
main 2
MyThread 2
MyThread 3
main 3
main 4
MyThread 4
main 5
MyThread 5

JAVA 多线程

原文:https://www.cnblogs.com/zhangxuechao/p/13616694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!