Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Start and Join a Thread #21

@Pfarrer

Description

@Pfarrer

https://www.baeldung.com/java-thread-join

class SampleThread extends Thread {
    public String status = getName() + ": inital";
    
    @Override
    public void run() {
        status = getName() + ": started";
        try { Thread.sleep(10); } catch (InterruptedException e) {}
        status = getName() + ": done";
    }
}

public class Main {
    public static void main(String[] args) throws InterruptedException {
        SampleThread t = new SampleThread();
        System.out.println(t.status);
        
        t.start();
        Thread.sleep(1); 
        System.out.println(t.status);
        
        t.join();
        System.out.println(t.status);
    }
}

Expected output:

Thread-0: inital
Thread-0: started
Thread-0: done

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions