Advertisement
sergAccount

Untitled

Jan 30th, 2021
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 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.app5;
  7.  
  8. /**
  9.  *
  10.  * @author Admin
  11.  */
  12. public class Main {
  13.  
  14.     public static void main(String[] args) {
  15.         // использование прерывания потока выполнения        
  16.         Thread th1 = new Thread(new MyTask());
  17.         th1.start();
  18.         // используем sleep для того чтобы задача выпол-сь некоторое время
  19.         try {
  20.             Thread.sleep(2000);
  21.         } catch (InterruptedException ex) {
  22.             ex.printStackTrace();          
  23.         }
  24.         // используем interrupt для прерывания потока выполнения
  25.         th1.interrupt();
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement