Advertisement
sergAccount

Untitled

Mar 21st, 2021
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 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. import java.util.concurrent.TimeUnit;
  9.  
  10. /**
  11.  *
  12.  * @author Admin
  13.  */
  14. public class MyTask2 implements Runnable {
  15.  
  16.     @Override
  17.     public void run() {
  18.  
  19.         System.out.println("MyTask2.run>>");
  20.         // trycatch + tab
  21.         for (int i = 0; i < 10; i++) {            
  22.             System.out.println("MyTask2.i=" + i);
  23.             try {
  24.                 //Thread.sleep(2000);
  25.                 TimeUnit.SECONDS.sleep(2);
  26.             } catch (InterruptedException e) {
  27.                 e.printStackTrace();
  28.                 // 1) завершаем работу задачи в случае InterruptedException
  29.                 // 2) продолжить                
  30.                 //break;
  31.             }
  32.         }
  33.         System.out.println("MyTask2<<");
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement