• Java8-Thread-No.01


    import java.util.concurrent.TimeUnit;
    
    public class Threads1 {
    
        public static void main(String[] args) {
            test1();
    //        test2();
    //        test3();
        }
    
        private static void test3() {
            Runnable runnable = () -> {
                try {
                    System.out.println("Foo " + Thread.currentThread().getName());
                    TimeUnit.SECONDS.sleep(1);
                    System.out.println("Bar " + Thread.currentThread().getName());
                }
                catch (InterruptedException e) {
                    e.printStackTrace();
                }
            };
    
            Thread thread = new Thread(runnable);
            thread.start();
        }
    
        private static void test2() {
            Runnable runnable = () -> {
                try {
                    System.out.println("Foo " + Thread.currentThread().getName());
                    Thread.sleep(1000);
                    System.out.println("Bar " + Thread.currentThread().getName());
                }
                catch (InterruptedException e) {
                    e.printStackTrace();
                }
            };
    
            Thread thread = new Thread(runnable);
            thread.start();
        }
    
        private static void test1() {
            Runnable runnable = () -> {
                String threadName = Thread.currentThread().getName();
                System.out.println("Hello " + threadName);
            };
    
            runnable.run();
    
            Thread thread = new Thread(runnable);
            thread.start();
    
            System.out.println("Done!");
        }
    }
    
  • 相关阅读:
    快速指引(CDH6.3.2)
    gRpc 跨语言调用(NetCore 与 Spring Boot)
    Windows 极简利器
    Jenkins 于Docker 中源配置
    Kettle 问题
    在 Ubuntu 下直接将二进制文件制作成 rpm 包
    麒麟常见问题
    基于jssip的简单封装
    带有handleEvent的eventEmitter
    js集锦
  • 原文地址:https://www.cnblogs.com/bilaisheng/p/10210918.html
Copyright © 2020-2023  润新知