lamada表达式创建多线程

# 实现runnable接口
Runnable runnable = () -> {
            int i = 0;
            for(;;){
                if(i < 11){
                    System.out.println("hello world"+i);
                    i++;
                }else{
                    break;
                }
            }
        };
        runnable.run();
        Thread thread = new Thread(runnable);
        thread.start();
# 继承Thread类
new Thread(()->{
            int i = 0;
            for(;;){
                if(i < 11){
                    System.out.println("hello world"+i);
                    i++;
                }else{
                    break;
                }
            }
        }).start();
发布了831 篇原创文章 · 获赞 387 · 访问量 278万+

猜你喜欢

转载自blog.csdn.net/AinUser/article/details/103363958
今日推荐