Advertisement
sergAccount

Untitled

Mar 21st, 2021
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.app24;
  7.  
  8. //
  9. import java.util.concurrent.TimeUnit;
  10.  
  11. public class Main {
  12.  
  13.     public static void main(String[] args) {
  14.         //
  15. //        Thread th = new Thread(new MyTask());
  16. //        th.start();        
  17.         // создаем поток и запускаем его с помощью метода start()  
  18.         //new Thread(new MyTask()).start();
  19.         // использование лямбда-вырвжения для реализации метода run()
  20.         Runnable r = () -> {
  21.             System.out.println("MyTaskLambda.run>>");
  22.             try {
  23.                 //Thread.sleep(2000);
  24.                 TimeUnit.SECONDS.sleep(2);
  25.             } catch (InterruptedException e) {
  26.                 e.printStackTrace();
  27.             }
  28.             System.out.println("<<");
  29.         };
  30.         new Thread(r).start();
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement