码迷,mamicode.com
首页 > 编程语言 > 详细

java 多线程

时间:2019-06-26 01:16:03      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:https   over   read   void   ack   mat   csharp   lis   test   

import  java.util.*;
        import java.text.*;

class MyRunnable  implements Runnable {
    @Override
    public void run() {

        System.out.println("in MyRunnable run");
    }
}

class MyThread extends Thread {

    public MyThread(Runnable runnable){
        super(runnable);
    }

    @Override
    public void run() {
        Date dNow = new Date( );
        SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
        String time=ft.format(dNow);
        System.out.println("in MyThread run");
        System.out.println(time);
    }
}
public class ThreadTest {
    //https://www.journaldev.com/1016/java-thread-example
    public static void main(String[] args) {
        List<Thread> list = new ArrayList<Thread>();
        Runnable myRunnable = new MyRunnable();

        for (int i = 0; i < 10000; i++) {
            Thread thread = new MyThread(myRunnable);
            thread.start();
            list.add(thread);
        }
        for(Thread o: list) {
            try {
                o.join();
            }catch (Exception E){
                E.printStackTrace();
            }
        }
        System.out.println("main finished ...");
    }

}

  

java 多线程

标签:https   over   read   void   ack   mat   csharp   lis   test   

原文地址:https://www.cnblogs.com/SunshineKimi/p/11087524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!