/
Andrey_java_edu
/
multithreading
Обзор
Документация
Войти
/
Andrey_java_edu
/
multithreading
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/kamenskiy/io/JoinExample.java
32 строки
914 B
AndreyJavaEdu
Проверили как работает метод join()
10 май 2024, 18:29
10 май 2024, 18:29
5de498a
Код
Авторство
О чём код?
package com.kamenskiy.io; public class JoinExample extends Thread{ public JoinExample(String name) { super(name); } @Override public void run() { String currentThread = Thread.currentThread().getName(); for (int i = 1; i < 10; i++) { System.out.println(currentThread + " is running: " + i); try { Thread.sleep(500); } catch (InterruptedException e) { throw new RuntimeException(e); } } System.out.println("Thread is completed: " + currentThread); } public static void main(String[] args) throws InterruptedException { Thread thread1 = new JoinExample("A"); Thread thread2 = new JoinExample("B"); Thread thread3 = new JoinExample("C"); thread1.start(); thread1.join(); thread2.start(); thread3.start(); } }