- Creating threads
- Thread lifecycle
- sleep and join
- Thread: Unit of execution
- Runnable: Functional interface for thread task
- sleep/join: Control thread timing and ordering
- ThreadDemo.java - Basic thread example
- ExtendingThreadDemo.java - Create a thread by extending
Thread - RunnableThreadDemo.java - Create a thread by implementing
Runnable - SleepJoinDemo.java - Demonstrates
sleepandjoin
- Compile:
javac *.java - Run:
java ThreadDemo(or any of the other classes)
- Create a thread using both approaches
- Use
sleepto simulate work - Use
jointo wait for completion
Next Day: Day 35 - Thread Synchronization