Package modernfeatures.java21
Class ThreadJoinAndStatusDemo
java.lang.Object
modernfeatures.java21.ThreadJoinAndStatusDemo
Demonstrates joining and checking the status of both classic (platform) threads and virtual threads in Java 21+.
This example launches multiple classic and virtual threads, waits for them to finish using join()
,
and then prints their final state to illustrate thread lifecycle management.
Key features demonstrated:
- Creating and starting classic (platform) threads and virtual threads
- Tracking threads with a list for later joining
- Using
join()
to wait for thread completion - Checking and displaying thread state after joining
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ThreadJoinAndStatusDemo
public ThreadJoinAndStatusDemo()
-
-
Method Details
-
main
Main method: launches, tracks, joins, and checks the status of both platform and virtual threads.- Parameters:
args
- command-line arguments (not used)- Throws:
InterruptedException
- if joining is interrupted
-