IT-Academy

Join Thread

Aug 14th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 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 sk.academy.it;
  7.  
  8. /**
  9.  * Poznamky a tipy ku skoleniu <b>ThreadJoin</b>
  10.  *
  11.  * @author Miroslav
  12.  * @version 1.0
  13.  * @since 15.10.2012
  14.  * @see <a href="http://www.it-academy.sk">www.it-academy.sk</a>
  15.  */
  16. public class ThreadJoin implements Runnable {
  17.  
  18.     public void run() {
  19.         try {
  20.             Thread.sleep(10000);
  21.         } catch (InterruptedException e) {
  22.         }
  23.     }
  24.  
  25.     public static void main(String[] args) throws InterruptedException {
  26.         Thread podproces = new Thread(new ThreadJoin());
  27.         podproces.start();
  28.         System.out.println(
  29.                 "cakam na dokoncenie spusteneho podprocesu 4 sekundy");
  30.         // Cakanie na dokoncenie procesu
  31.         podproces.join(4000);
  32.         // Testujem ci je vlakno aktivne
  33.         if (podproces.isAlive()) {
  34.             System.out.println(
  35.                     "cakal som, ale podproces sa este neskoncil");
  36.         } else {
  37.             System.out.println(
  38.                     "podproces skoncil vykonavanie svojej cinnosti");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment